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

发布于 2024-11-24 03:22:39 字数 1297 浏览 0 评论 0原文

我编写了一个MFC Extension DLL,输入它并使用导出的Function就可以了;

但是当我退出应用程序时,在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;
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九八野马 2024-12-01 03:22:39

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

马丁

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文