释放 MFC Ext DLL @ dllmodul.cpp 时出现断言错误 #230
我编写了一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您未能在 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