难题,新线程中定义一个对话框,在doMal()时失败
zteeb 2003-08-22 10:54:27 我的程序是一个MFC对话框程序,需要在按下某个Button后,启动另一个线程,并且在这个新线程中在定义一个对话框someDlg供用户填写一些东西,但运行someDlg.DoModal()时,总会在wincore.cpp的CWnd::AssertValid() 函数中的下列地方出现错误,即p!=this,我把someDlg定义为全局变量也同样通不过。后来发现在整个Assert下面有如下注释,好像是说这个错误是由于我在两个线程间传递Cwnd对象造成的,但我的someDlg并没有在两个线程间传递啊?有哪个高手可以解释下面的意思吗?
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.