troubleshooting Question

CDialog::DoModal() in  amultithreaded application

Avatar of Krip
Krip asked on
Microsoft Development
10 Comments1 Solution1513 ViewsLast Modified:

I have A class derived from CDialog.
At some point in the program a random thread (A socket's threadpool) would create a new instance of that class (I tried heap and stack creation both) and calls DoModal() on it. At some point after it's created, the modal's pumpmessage ends up calling the modal's main window parent's PreTranslate (which is the application window) and when that PreTranslte calls CDialog::PreTransle it crashes in CWnd::AssertValid() just above MS's friendly note:

// 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.

I assure you I do nothing of the sort.

So what up???
Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros