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.