【发布时间】:2019-07-02 14:51:45
【问题描述】:
我在关闭应用程序时收到以下调试断言:
我调试了流程,发现断言发生在 CWnd::DestroyWindow()
// Should have been detached by OnNcDestroy
#ifdef _DEBUG
ASSERT(pMap->LookupPermanent(hWndOrig) == NULL);
我的类是从 COleControl 派生的,而 COleControl 又是从 CWnd 派生的。
对象创建在 .NET winform 中进行,在应用程序关闭时,对象析构函数被调用并且断言即将到来。
我尝试过的事情:
1) 在我的类析构函数上调用 DestroyWindow() :没用
2) 像下面这样重写 OnFinalRelease 并且它起作用了:
void CSimple::OnFinalRelease()
{
if (!m_bFinalReleaseCalled)
{
m_bFinalReleaseCalled = TRUE;
ReleaseCaches();
CWnd::OnNcDestroy(); --> explicitly called OnNcDestroy()
if (m_hWnd != NULL)
DestroyWindow();
CCmdTarget::OnFinalRelease();
}
我不确定这是否是正确的解决方法。我也不确定问题是否出在 .NET 方面。
【问题讨论】:
标签: .net debugging visual-c++ mfc assert