Click here to Skip to main content
12,997,060 members (52,737 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 5 Jun 2003

A Simple Resource Manager

, 5 Jun 2003
Rate this:
Please Sign up or sign in to vote.
This is a simple class that you can use to load and use another resource DLL if it is present during runtime.


I have created this class to help me load a different resource DLL if it is present during runtime. An example would be a multi-language application. If another resource DLL (with a name specified at compile time) is present, it can load and use it as the resource for the application.

Let's look at the class header. It is quite simple and I think the comments describe well about the individual methods.

class CResourceManager  
// Operations

    // Constructor

    // Destructor
    virtual ~CResourceManager();

    // Load external resource dll. If file not present or unable to load,
    // it returns FALSE. If it is present, it is loaded but does not affect
    // the default resource of the application. You should call this if you
    // want to manage the current application resource and an external one.
    BOOL Setup(CString);

    // Load external resource dll and set it as default for application.
    // Before setting as default, the current resource handle is stored
    // in case when you need to access the resource there.
    // If file not present or unable to load, the current application
    // resource is being used. 
    BOOL SetupEx(CString);

    // Get string from string table of external resource if any
    // If there is an external resource loaded, GetString will retrieve from
    // there. If not, it will retrieve from the application default resource.
    CString GetString(UINT);

// Attributes

    HINSTANCE m_hExternalResource; // Handle to external resource loaded
    HINSTANCE m_hApplicationResource; // Handle to current application resource

Using the code

Below is an example of how you may use the methods of the class. First you need to create an object of CResourceManager. You can put it as global or as a member of your application class. Then, call the Setup(...) method in InitInstance(...) as shown below.

BOOL CtestApp::InitInstance()
    // InitCommonControls() is required on Windows XP if an application
    // manifest specifies use of ComCtl32.dll version 6 or later to enable
    // visual styles.  Otherwise, any window creation will fail.


    // Initialize OLE libraries
    if (!AfxOleInit())
        return FALSE;

    // Load and set the specified resource dll as default if it is present.
    // Normally the location of the dll would be the same as the executable
    // and you would need to determine it with GetModuleFileName(...), but
    // in this case, i assume i know where the dll is located.

    // The one and only window has been initialized, so show and update it
    // call DragAcceptFiles only if there's a suffix
    //  In an SDI app, this should occur after ProcessShellCommand
    return TRUE;

As for cleaning up the loaded resource DLL, the destructor will handle it as shown below.

    // Check if handle is valid, free library
    if (m_hExternalResource != NULL)

    // Init handles
    m_hExternalResource = NULL;
    m_hApplicationResource = NULL;

Points of interest

I admit that this class do fall short in terms of the other resource problems that could be addressed, but feel free to extend it if you want. :)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Weiye Chen
Singapore Singapore
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralAre you the one!!!!!111 Pin
saajan18-May-04 2:30
membersaajan18-May-04 2:30 
GeneralRe: Are you the one!!!!!111 Pin
Weiye Chen20-May-04 5:05
memberWeiye Chen20-May-04 5:05 
GeneralPlease provide a demo application. Pin
John M. Drescher7-Jun-03 4:31
memberJohn M. Drescher7-Jun-03 4:31 
GeneralBroken link. Pin
WREY7-Jun-03 2:21
memberWREY7-Jun-03 2:21 
GeneralRe: Broken link. Pin
Weiye Chen7-Jun-03 3:15
memberWeiye Chen7-Jun-03 3:15 
GeneralSomething handy to have around. Pin
WREY7-Jun-03 4:00
memberWREY7-Jun-03 4:00 
GeneralRe: Something handy to have around. Pin
Weiye Chen7-Jun-03 4:25
memberWeiye Chen7-Jun-03 4:25 
GeneralRe: Something handy to have around. Pin
Anton Heidelwalder28-Oct-04 4:54
memberAnton Heidelwalder28-Oct-04 4:54 
GeneralRe: Something handy to have around. Pin
WREY28-Oct-04 7:02
memberWREY28-Oct-04 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 6 Jun 2003
Article Copyright 2003 by Weiye Chen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid