.exe/wincore.cpp 中的调试断言失败

发布于 2024-10-16 19:07:56 字数 1289 浏览 5 评论 0原文

我正在用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 技术交流群。

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

发布评论

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

评论(2

好倦 2024-10-23 19:07:56

我认为这个问题与不恰当地使用 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.

变身佩奇 2024-10-23 19:07:56

问题很可能是在某个地方调用 CWnd::GetSafeHwnd() ,并且在窗口被销毁时仍在使用该 HWND 句柄。换句话说,您正在销毁一个 CWnd,而该 CWnd 的句柄在其他地方仍然处于活动状态。

一种解决方案是重写virtual BOOL DestroyWindow(),并确保在那里释放句柄。

例如,如果您要从 Acrobat 插件显示模式对话框,则必须将窗口句柄传递给 Acrobat,以让它知道您处于模式模式:

int CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if(CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;
    // Put Acrobat into modal dialog mode
    m_AVdlgWin = AVWindowNewFromPlatformThing(AVWLmodal, 0, NULL, gExtensionID, GetSafeHwnd());
    AVAppBeginModal(m_AVdlgWin);
    AVWindowBecomeKey(m_AVdlgWin);
    return 0;
}

当然,您需要执行相反的操作DestroyWindow,以确保释放内部句柄:

BOOL CMyDialog::DestroyWindow()
{
    // Take Acrobat out of modal dialog mode, and release our HWND
    AVAppEndModal();
    AVWindowDestroy(m_AVdlgWin);
    return CDialog::DestroyWindow();
}

此示例假设 CMyDialog 始终是模态的。

如果您无法释放由 GetSafeHwnd 获取的句柄,则会出现断言失败。释放手柄到底意味着什么取决于你用它做了什么。人们只能猜测。

The problem is most likely that somewhere you are calling CWnd::GetSafeHwnd(), and still using that HWND handle at the time the window is being destroyed. In other words, you're destroying a CWnd 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:

int CMyDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if(CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;
    // Put Acrobat into modal dialog mode
    m_AVdlgWin = AVWindowNewFromPlatformThing(AVWLmodal, 0, NULL, gExtensionID, GetSafeHwnd());
    AVAppBeginModal(m_AVdlgWin);
    AVWindowBecomeKey(m_AVdlgWin);
    return 0;
}

Of course you need to perform the opposite in DestroyWindow, to make sure the internal handle is released:

BOOL CMyDialog::DestroyWindow()
{
    // Take Acrobat out of modal dialog mode, and release our HWND
    AVAppEndModal();
    AVWindowDestroy(m_AVdlgWin);
    return CDialog::DestroyWindow();
}

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.

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