开发者

Assertion Error when Release the MFC Ext DLL @ dllmodul.cpp #230

开发者 https://www.devze.com 2023-03-19 16:42 出处:网络
I programmed a MFC Extension DLL, it was all right when entering it and using the exported Function; But When I exit the application, during the DLL release the DLL, it threw a Assertion Error,then I

I programmed a MFC Extension DLL, it was all right when entering it and using the exported Function;

But When I exit the application, during the DLL release the DLL, it threw a Assertion Error,then I following the error, found it stall at this:

extern "C"
BOOL WINAPI RawDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
     hInstance;
     if (dwReason == DLL_PROCESS_ATTACH)
     {
#ifdef _AFXDLL
// make sure we have enough memory to attempt to start (8kb)
          void* pMinHeap = LocalAlloc(NONZEROLPTR, 0x2000);
          if (pMinHeap == NULL)
               return FALSE; // fail if memory alloc fails
          LocalFree(pMinHeap);

          // set module state before initialization
          _AFX_THREAD_STATE* pState = AfxGetThreadState();
          pState->m_pPrevModuleState = AfxSetModuleState(&afxModuleState);
     }
     else if (dwReason == DLL_PROCESS_DETACH && !__mixedModuleStartup)
     {
          // restore module state after cleanup
          _AFX_THREAD_STATE* pState = AfxGetThreadState();

          // ************************************************
          VERIFY(AfxSetModuleState(pState->m_pPrevModuleState) ==
          &afxModuleState); // Where Error occurred 
          // ************************************************

          DEBUG_ONLY(pState->m_pPrevModuleState = NULL);

#endif //_AFXDLL
     }
     开发者_C百科return TRUE;
}


You have failed to use AFX_MANAGE_STATE correctly on all entry points to your DLL. So your module state is wrong, hence the assert.

Martyn

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号