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:

ASSERT(AfxGetModuleState() != AfxGetAppModuleState());


VERIFY(AfxSetModuleState(AfxGetThreadState()->m_pPrevModuleState) == &afxModuleState);

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)