将HWND传递给DLL后断言失败

时间:2014-08-20 20:51:08

标签: c++ winapi dll mfc

在我们的应用程序中,我们在DLL中有专门的模块,可以控制主应用程序窗口中的窗口。我们将窗口作为HWND传递,而不是CWnd*。在DLL内部,我使用CWnd::FromHandle来获取CWnd *,我用它作为父窗口在该窗口内创建CHtmlView

只要显示此视图,就会在wincore.cpp中发生调试声明:

    if(pMap)
    {
        ASSERT( (p = pMap->LookupPermanent(m_hWnd)) != NULL ||
                (p = pMap->LookupTemporary(m_hWnd)) != NULL);
    }
    ASSERT((CWnd*)p == this);   // must be us

    // Note: if either of the above asserts fire and you are
    // writing a multithreaded application, it is likely that
    // you have passed a C++ object from one thread to another
    // and have used that object in a way that was not intended.
    // (only simple inline wrapper functions should be used)
    //
    // In general, CWnd objects should be passed by HWND from
    // one thread to another.  The receiving thread can wrap
    // the HWND with a CWnd object by using CWnd::FromHandle.
    //
    // It is dangerous to pass C++ objects from one thread to
    // another, unless the objects are designed to be used in
    // such a manner.

这里与LookupTemporary的行失败了,尽管我完全按照评论中的描述使用它。在发布模式下,或者如果我只在我的视图类中放置一个空AssertValid - 方法,一切正常。

我的问题:这怎么可能发生,这是我应该关心的事情吗?

0 个答案:

没有答案