释放MFC Ext DLL @ dllmodul.cpp#230时出现断言错误

时间:2011-07-13 04:13:57

标签: c++ visual-studio-2008 visual-c++ mfc

我编写了一个MFC扩展DLL,在输入它并使用导出的函数时没问题;

但是当我退出应用程序时,在DLL发布DLL期间,它抛出了一个断言错误,然后我跟着错误,发现它停在这个:

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
     }
     return TRUE;
}

2 个答案:

答案 0 :(得分:0)

您无法在DLL的所有入口点上正确使用AFX_MANAGE_STATE。所以你的模块状态是错误的,因此断言。

马丁

答案 1 :(得分:0)

Assertion Failed对话框永远不会出现在Release版本中。确保DLL和EXE都是发布版本。