}至于为什么,参看 如下说明:( wincore.cpp,page 887)// 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.
....void B(CMyDlg* myDlg)
{
....
myDlg.UpdateData(FALSE); // exception!!!
}
放到对话框类的函数A中调用了CreateThread函数
的后面不行吗??干吗要在线程中update呢??如果一定要可能是句柄没传过去
{ //传句柄
h=::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)B, this->m_hWnd,0 ,&dwThreadId);}
//extern COneDlg * mydlg2;
void B(HWND myDlg)
{
COneDlg *dlg;
// 把句柄转换为对象
dlg=(COneDlg *)CWnd::FromHandle(myDlg);
dlg->UpdateData(FALSE);
}至于为什么,参看 如下说明:( wincore.cpp,page 887)// 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.
{
CWnd * pWnd = CWnd::FromHandle((HWND)pParam);
CWnd * pParent = pWnd->GetTopLevelParent();
... ...
}传指针不好控制!
但是不能用pWnd访问其成员变量,例如:
pWnd->m_strData = "xxxx"; // 马上当掉