.exe/wincore.cpp 中的调试断言失败
我正在用VC++ 6.0做一个RT模拟器。无论何时执行,在开放架构计算机(OAC,即飞行中的总线控制器)打开的情况下,程序都能正常执行。但当 OAC 打开时,程序在 Debug/.exe/wincore.cpp 的第 1 行处给出“调试断言失败”。 980.可能是什么问题?如果可能的话请提供解决方案。
这是完整的 DestroyWindow 函数。
BOOL CWnd::DestroyWindow()
{
if (m_hWnd == NULL)
return FALSE;
CHandleMap* pMap = afxMapHWND();
ASSERT(pMap != NULL);
CWnd* pWnd = (CWnd*)pMap->LookupPermanent(m_hWnd);
#ifdef _DEBUG
HWND hWndOrig = m_hWnd;
#endif
#ifdef _AFX_NO_OCC_SUPPORT
BOOL bResult = ::DestroyWindow(m_hWnd);
#else //_AFX_NO_OCC_SUPPORT
BOOL bResult;
if (m_pCtrlSite == NULL)
bResult = ::DestroyWindow(m_hWnd);
else
bResult = m_pCtrlSite->DestroyControl();
#endif //_AFX_NO_OCC_SUPPORT
// Note that 'this' may have been deleted at this point,
// (but only if pWnd != NULL)
if (pWnd != NULL)
{
// Should have been detached by OnNcDestroy
#ifdef _DEBUG
//////////////////////////////HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!///////////////////
ASSERT(pMap->LookupPermanent(hWndOrig) == NULL); //line 980
#endif
}
else
{
#ifdef _DEBUG
ASSERT(m_hWnd == hWndOrig);
#endif
// Detach after DestroyWindow called just in case
Detach();
}
return bResult;
}
I am doing an RT simulator in VC++ 6.0. whenever it is executed, without the Open Architecture Computer(OAC,it is the Bus Controller in the Flight) switched on, the program executes properly. But with the OAC ON, the program is giving Debug assertion failed- in Debug/.exe/wincore.cpp at line no. 980. what may be the problem? Please provide with the solution if possible.
This is the copmlete DestroyWindow function.
BOOL CWnd::DestroyWindow()
{
if (m_hWnd == NULL)
return FALSE;
CHandleMap* pMap = afxMapHWND();
ASSERT(pMap != NULL);
CWnd* pWnd = (CWnd*)pMap->LookupPermanent(m_hWnd);
#ifdef _DEBUG
HWND hWndOrig = m_hWnd;
#endif
#ifdef _AFX_NO_OCC_SUPPORT
BOOL bResult = ::DestroyWindow(m_hWnd);
#else //_AFX_NO_OCC_SUPPORT
BOOL bResult;
if (m_pCtrlSite == NULL)
bResult = ::DestroyWindow(m_hWnd);
else
bResult = m_pCtrlSite->DestroyControl();
#endif //_AFX_NO_OCC_SUPPORT
// Note that 'this' may have been deleted at this point,
// (but only if pWnd != NULL)
if (pWnd != NULL)
{
// Should have been detached by OnNcDestroy
#ifdef _DEBUG
//////////////////////////////HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!///////////////////
ASSERT(pMap->LookupPermanent(hWndOrig) == NULL); //line 980
#endif
}
else
{
#ifdef _DEBUG
ASSERT(m_hWnd == hWndOrig);
#endif
// Detach after DestroyWindow called just in case
Detach();
}
return bResult;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这个问题与不恰当地使用 CWnd::FromHwnd 有关,例如存储结果指针并稍后使用它。如果必须存储某些内容,则应该是 HWND,而不是 CWnd*。
另一个问题可能是在一个线程中创建窗口并在另一个线程中销毁它。
I think this problem has something to do with using CWnd::FromHwnd inappropriately, like storing the resulting pointer, and using it later. If something must be stored, it should be HWND, not CWnd*.
Another issue might be creating window in one thread and destroying it in another.
问题很可能是在某个地方调用 CWnd::GetSafeHwnd() ,并且在窗口被销毁时仍在使用该 HWND 句柄。换句话说,您正在销毁一个 CWnd,而该 CWnd 的句柄在其他地方仍然处于活动状态。
一种解决方案是重写
virtual BOOL DestroyWindow()
,并确保在那里释放句柄。例如,如果您要从 Acrobat 插件显示模式对话框,则必须将窗口句柄传递给 Acrobat,以让它知道您处于模式模式:
当然,您需要执行相反的操作
DestroyWindow
,以确保释放内部句柄:此示例假设 CMyDialog 始终是模态的。
如果您无法释放由
GetSafeHwnd
获取的句柄,则会出现断言失败。释放手柄到底意味着什么取决于你用它做了什么。人们只能猜测。The problem is most likely that somewhere you are calling
CWnd::GetSafeHwnd()
, and still using thatHWND
handle at the time the window is being destroyed. In other words, you're destroying aCWnd
whose handle is still active somewhere else.One solution is to override
virtual BOOL DestroyWindow()
, and make sure you release your handle there.For example, if you're showing a modal dialog box from an Acrobat plug-in, you have to pass your window handle to Acrobat, to let it know that you're in modal mode:
Of course you need to perform the opposite in
DestroyWindow
, to make sure the internal handle is released:This example assumes CMyDialog is always modal.
If you fail to release a handle obtained by
GetSafeHwnd
, that's when you get the assertion failure. What exactly releasing a handle means depends on what you did with it. One can only guess.