debug assertion failed during mfc regular dll startup
I'm working on a project that's using an mfc regular dll from a Qt gui project(yes, you don't see wrong), the mfc dll code is extracted from some other projects build entirely in mfc. I build all the mfc code with a regular dll and run it, and it came to the debug assertion during the initialization at the code:
furthermore, when i ignore and continue running the programme, a debug assertion failed at the code:
ASSERT(afxCurrentResourceHandle != NULL,
of course the resource handle is null.
I track down the source code, and it seems that during the initialization, the 'dllmain'(in fact there is a lot of 'dllmains') in my dll has been invoked twice and only the seconde time the assert has been emitted, the first time it has been running ok. and I notice that the members in the global variable afxModuleState has all been null thus cause the assertion after the initialization, and what's more I notice that during the first time initialization, the afxModuleState has been assigned right.
I wonder what's the cause of my problem and how to solve it. And I'm willing to hear your advice.
an additional information is that, in my regular dll, I use boost library(which I'm not too familiar with)
Sorry for bringing up an old topic but I have this problem as well and I don't understand it, even after reading the site referred to.
My situation is I have a DLL that works fine initially. Then I begin using a 3rd party lib file statically linked into my dll. As long as I don't reference anything in the library my code still compiles, links and runs without any problem. But as soon as I include a single line using the library I get the crash on startup as well. My callstack is this:
> mfc90d.dll!AfxCoreInitModule() Line 587 + 0x23 bytes C++
ControlClient.dll!InternalDllMain(HINSTANCE__ * hInstance=0x06e20000, unsigned long dwReason=1, void * __formal=0x00000000) Line 88 C++
ControlClient.dll!DllMain(HINSTANCE__ * hInstance=0x06e20000, unsigned long dwReason=1, void * lpReserved=0x00000000) Line 272 C++
ControlClient.dll!__DllMainCRTStartup(void * hDllHandle=0x06e20000, unsigned long dwReason=1, void * lpreserved=0x00000000) Line 546 + 0x11 bytes C
ControlClient.dll!_DllMainCRTStartup(void * hDllHandle=0x06e20000, unsigned long dwReason=1, void * lpreserved=0x00000000) Line 510 + 0x11 bytes C
(and so on into other system libraries)
So the crash is on startup before I ever get a chance to use the AFX_MANAGE_STATE(AfxGetStaticModuleState()) macro.
Can someone explain this in more detail? Because I don't understand it from the MSDN explanation (which as far as I can see doesn't offer any explanation on exactly when you need to do this).