MFC Extension Dlls - loading screws up the resource chain...
-
Hi! I'm having quite annoying problems when dynamically loading libraries of the type "MFC Expansion Dll". After I load an optional dll at runtime via AfxLoadLibrary(), my main window fails to locate its resources. Interestingly enough, dialogs are constructed OK, but fail when doing data exchange (when using GetDlgItem() I assume). This happens even when I unload the optional dll again (AfxFreeLibrary()) before creating any main window dlls. As far as I understand it, this should remove the loaded Dll from the resource chain, but it never seems to happen (The AfxTermExtensionModule() function is called though). I tried to 'correct' the resource handle via AfxSetResourceHandle() but nothing changed at all. Has anyone had similar problems and can give me a hint what's wrong? Thanks, Nick
-
Hi! I'm having quite annoying problems when dynamically loading libraries of the type "MFC Expansion Dll". After I load an optional dll at runtime via AfxLoadLibrary(), my main window fails to locate its resources. Interestingly enough, dialogs are constructed OK, but fail when doing data exchange (when using GetDlgItem() I assume). This happens even when I unload the optional dll again (AfxFreeLibrary()) before creating any main window dlls. As far as I understand it, this should remove the loaded Dll from the resource chain, but it never seems to happen (The AfxTermExtensionModule() function is called though). I tried to 'correct' the resource handle via AfxSetResourceHandle() but nothing changed at all. Has anyone had similar problems and can give me a hint what's wrong? Thanks, Nick
MFC keeps a CDynLinkLibrary linked list of dynamic DLL it has loaded. Your extension DLL probably has not properly removed itself from this chain. It also seems it has some resources with the same identifiers as your main program. You will have to walk this chain and manually remove the offending DLL's entry, if it is not being removed when you call the AfxUnloadLibrary. MFC walks a chain of laoded DLL and stops at the first resource it find, from one of the dynamically loaded DLL, so you need to break the links so that the resources in your DLL are not used isntead of your main program. Now, not sure why the SetReosurceHandle is not working, except maybe MFC is still giving priority to one of the DLL, or you set the resource handle from a different thread, since it is thread-specific.
-
MFC keeps a CDynLinkLibrary linked list of dynamic DLL it has loaded. Your extension DLL probably has not properly removed itself from this chain. It also seems it has some resources with the same identifiers as your main program. You will have to walk this chain and manually remove the offending DLL's entry, if it is not being removed when you call the AfxUnloadLibrary. MFC walks a chain of laoded DLL and stops at the first resource it find, from one of the dynamically loaded DLL, so you need to break the links so that the resources in your DLL are not used isntead of your main program. Now, not sure why the SetReosurceHandle is not working, except maybe MFC is still giving priority to one of the DLL, or you set the resource handle from a different thread, since it is thread-specific.
Thanks for the reply. It shed light on some details I wasn#t aware of. Anyway, I discovered that, for some reason, the dll was not unloaded at all (the statement was never executed due to some weird conditions I still don't get). Restructuring the code lead to unloading of the dll and now all works smoothly. It can be so simple sometimes... Nevertheless I got some more insight in the works behind the scenes, so this experience wasn't completely useless ;) Nick