我是编写了一个DLL的弹窗,然后MFC应用程序去调用就出现了这个问题:
关于这个问题主要问题点在 ASSERT(pMap != NULL); ASSERT((CWnd*)p == this); // must be us
这两个问题在release版本的时候并不展现,但并不代表没有问题:
出问题的源码如下:
#ifdef _DEBUG
void CWnd::AssertValid() const
{
if (m_hWnd == NULL)
return; // null (unattached) windows are valid
// check for special wnd??? values
ASSERT(HWND_TOP == NULL); // same as desktop
if (m_hWnd == HWND_BOTTOM)
ASSERT(this == &CWnd::wndBottom);
else if (m_hWnd == HWND_TOPMOST)
ASSERT(this == &CWnd::wndTopMost);
else if (m_hWnd == HWND_NOTOPMOST)
ASSERT(this == &CWnd::wndNoTopMost);
else
{
// should be a normal window
ASSERT(::IsWindow(m_hWnd));
// should also be in the permanent or temporary handle map
CHandleMap* pMap = afxMapHWND();
ASSERT(pMap != NULL);
CObject* p=NULL;
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.
}
}
#endif
网上的资料大都说是多线程引起的,其实我没有多线程,只是有子窗口;只是MFC本身消息机制问题导致的,我的部分代码是这样写的:
代码里都是这种风格的,然后百思不得其解,仍然没有解决问题,实在没有办法了;最后对于窗口DLL又重新封装了一遍,类似这样:
重新编写之后就可以了!
来源:CSDN
作者:奥特曼VS怪兽
链接:https://blog.csdn.net/yuchu123456/article/details/104050012