Click here to Skip to main content
Click here to Skip to main content

DllInstanceSwitcher class for switching to MFC Extension DLL resources

By , 18 Jul 2002
 

Introduction

Some time ago I wrote an MFC Extension DLL. This DLL contained CMDIFrameWnd derived class with CToolbar placed on it. After dynamically loading this DLL into main application I saw that toolbar tool-tip strings loaded from the main application resources, because they have string IDs equal to DLL strings IDs.

Macro AFX_MANAGE_STATE(AfxGetStaticModuleState()) doesn't work because Microsoft don't want us to use it.

The solution is to write own resource switcher class and create it everywhere we need to use Extension DLL resources. Here is the code of this class:

extern "C" AFX_EXTENSION_MODULE ExtensionDLL;
class DllInstanceSwitcher
{
public:
    DllInstanceSwitcher()
    {
        m_hInst = AfxGetResourceHandle();
        AfxSetResourceHandle(ExtensionDLL.hResource);
    }

    ~DllInstanceSwitcher()
    {
        AfxSetResourceHandle(m_hInst);
    }

private:
    HINSTANCE m_hInst;
};

#define SWITCH_RESOURCE  DllInstanceSwitcher __SwitchInstance;

Also we need to replace declaration of:

static AFX_EXTENSION_MODULE someDLL = { NULL, NULL }

with

extern "C" AFX_EXTENSION_MODULE ExtensionDLL = { NULL, NULL }

And all we need is to insert SWITCH_RESOURCE; everywhere we want to use DLL resources.

License

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

Peredelsky Alexey
Web Developer
Russian Federation Russian Federation
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalhelpmemberguyuewuhua24 Sep '09 - 19:43 
GeneralMy vote of 1memberKarstenK23 Nov '08 - 20:54 
Questionshort example code?memberAnton Heidelwalder9 Nov '04 - 3:13 
AnswerRe: short example code?memberdickey wong29 Aug '05 - 9:03 
GeneralHi, Problems with MFC in a DLLmemberBeginnerOnline4 Dec '02 - 0:23 
Generalthanks a lotsussAnonymous8 Oct '02 - 3:27 
GeneralCommand ID'smemberPeredelsky Alexey14 Aug '02 - 2:33 
GeneralExtension DLL resource managementmemberGary R. Wheeler20 Jul '02 - 7:45 
GeneralRe: Extension DLL resource managementsussMichael Kuelshammer21 Jul '02 - 0:52 
GeneralRe: Extension DLL resource managementmemberPeredelsky Alexey21 Jul '02 - 20:26 
GeneralExample code neededsussMichael Kuelshammer20 Jul '02 - 7:16 
GeneralRe: Example code neededmemberPeredelsky Alexey21 Jul '02 - 20:33 
GeneralThat's useful!memberPhilip Patrick19 Jul '02 - 20:06 
GeneralI think it will not work in Win 98 & Memembermuayyad19 Jul '02 - 3:21 
GeneralRe: I think it will not work in Win 98 & MememberCraig Henderson19 Jul '02 - 4:01 
GeneralRe: I think it will not work in Win 98 & MememberPeredelsky Alexey19 Jul '02 - 4:25 
GeneralNice solutionmemberRoger Allen19 Jul '02 - 2:58 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 19 Jul 2002
Article Copyright 2002 by Peredelsky Alexey
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid