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

DllInstanceSwitcher class for switching to MFC Extension DLL resources

, 18 Jul 2002
Rate this:
Please Sign up or sign in to vote.
AFX_MANAGE_STATE(AfxGetStaticModuleState()) results in an error. This is the solution to the problem.


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:

class DllInstanceSwitcher
        m_hInst = AfxGetResourceHandle();


    HINSTANCE m_hInst;

#define SWITCH_RESOURCE  DllInstanceSwitcher __SwitchInstance;

Also we need to replace declaration of:




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


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
No Biography provided

Comments and Discussions

Generalhelp Pinmemberguyuewuhua24-Sep-09 20:43 
GeneralMy vote of 1 PinmemberKarstenK23-Nov-08 21:54 
Questionshort example code? PinmemberAnton Heidelwalder9-Nov-04 4:13 
Hallo Alexey!

The problem you describe is actually mine. But I am sorry, I do not understand, how to use your code. I tried to put your code to my samples, but without success. Could you give a short example?

Thanks Anton!
AnswerRe: short example code? Pinmemberdickey wong29-Aug-05 10:03 
GeneralHi, Problems with MFC in a DLL PinmemberBeginnerOnline4-Dec-02 1:23 
Generalthanks a lot PinsussAnonymous8-Oct-02 4:27 
GeneralCommand ID's PinmemberPeredelsky Alexey14-Aug-02 3:33 
GeneralExtension DLL resource management PinmemberGary R. Wheeler20-Jul-02 8:45 
GeneralRe: Extension DLL resource management PinsussMichael Kuelshammer21-Jul-02 1:52 
GeneralRe: Extension DLL resource management PinmemberPeredelsky Alexey21-Jul-02 21:26 
GeneralExample code needed PinsussMichael Kuelshammer20-Jul-02 8:16 
GeneralRe: Example code needed PinmemberPeredelsky Alexey21-Jul-02 21:33 
GeneralThat's useful! PinmemberPhilip Patrick19-Jul-02 21:06 
GeneralI think it will not work in Win 98 & Me Pinmembermuayyad19-Jul-02 4:21 
GeneralRe: I think it will not work in Win 98 & Me PinmemberCraig Henderson19-Jul-02 5:01 
GeneralRe: I think it will not work in Win 98 & Me PinmemberPeredelsky Alexey19-Jul-02 5:25 
GeneralNice solution PinmemberRoger Allen19-Jul-02 3:58 

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

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

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