Few years back, when I first written an MFC DLL with a resource (a dialog with few controls) surely it’s crashed on the first call. One of the senior members in the team came there to help me and with a magic statement, he just added a single line of code in each exported functions and amazingly the crash issue disappeared. Then on, in each and every export functions, I religiously used this magic statement.
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
As we all know the statement indicates windows that to search for the resources in the DLL instead of searching in the executable which is loaded the library. In other words, it allows distinguishing the resources in the exe and dll.
OK. That’s fine in the case of a normal MFC DLL. Now if you try the routine with MFC Exetension DLL, you may experience a link error.
error LNK2005: _DllMain@12 already defined in yourdll.obj
How we can remove this? A quick Googling provided me a link to Microsoft KB article
As per the article, what you’re doing with your MFC extension DLL is wrong. The solution is to remove the AFX_MANAGE_STATE call from your DLL. The following what indicated in the article.
This is incorrect. Extension DLLs do not need to add this macro at the top of every exported function . The AFX_MANAGE_STATE macro can be used inside of callbacks or custom window procedures to properly adjust the current module state, but it should be used with AfxGetAppModuleState() or a specific module state instance instead of AfxGetStaticModuleState().
So you just remove the call from the exported functions as MFC extension DLLs are not needed to use this expression. Any attempt to use AfxGetStaticModuleState( ) in an Extension DLL will result in possible run-time problems and the above indicated linker errors