照理说应该是没问题的呀,因为release运行没问题呀 我想弄明白为什么这样不行以下是调试运行时出错部份的代码,位于wincore.cpp当中: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); //这里是第900行 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. } }
从你的代码看,应该有问题
hwnd->UpdateData(true);
你这个hwnd是模式对话框还是非模式对话框呢?应该是模式对话框吧,把这行代码所在的函数贴出来看看吧,然后说明一下hwnd的定义。
hwnd->UpdateData(true);
语句正是处于这个线程函数这中部分代码如下:void Cmfc_testDlg::OnBnClickedButton1()//btn控件响应函数
{
DWORD dwTh1;
CreateThread(NULL,0,&start_send1,this,DEBUG_PROCESS,&dwTh1);//传递this指针
}
DWORD WINAPI start_send1(
LPVOID lpParameter // thread data
)
{
Cmfc_testDlg *hwnd = (Cmfc_testDlg *)lpParameter;//接收this指针并转换
//.......其他代码
hwnd->UpdateData(true);//这里出错
}
我想弄明白为什么这样不行以下是调试运行时出错部份的代码,位于wincore.cpp当中: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); //这里是第900行 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.
}
}
ASSERT(pMap != NULL); //这里是第900行