|
-
December 23rd, 2011, 08:32 PM
#1
CHandleMap
I've run into an interesting little stumbling block in the course of my coding adventures. I have been developing a multithreaded application. It worked fine on my old Windows x32 single core system. Now that I've ported it to a Windows x64 i5 dual core, I'm getting CWnd::AssertValid errors.
I did some research and MSDN says that if two diferent threads make windows, then the assertvalid can fire off. Is this true? It also said something about one thread giving a window handle to another thread. Does anyone have a coding example? What is the typically strategy that others usually take when creating windows in multi-threaded application? Do you normally make one thread that creates all the windows? This can get nasty, so I'd like some thoughts on this initial observation so that I can limit my search of little. Thank you.
Last edited by paradoxresolved; December 23rd, 2011 at 08:36 PM.
error C2146a : syntax error : nebulizer stained in the tower floppy apple rider. Go rubble in flee smite. Bleeble snip snip.
Documentation says: error C2146a - This means there is an error somewhere in the course of human endeavor. Fix in the usual way.
-
December 24th, 2011, 12:24 AM
#2
Re: CHandleMap
Do you normally make one thread that creates all the windows?
With MFC, yes. MFC window classes are not thread safe, so using those across threads may be a real pain, though still possible with a great effort and caution.
The main problem is using MFC window classes across threads. But in the context of the thread that created the window there must be no problem at all.
It also said something about one thread giving a window handle to another thread.
Indeed, plain Win API calls really are thread safe, so getting to that level could solve 99% of possible issues. For example, you need to update progress window from worker thread. Instead of passing MFC object, pass its bare window handle to the thread, and use it as is, i.e. make winapi calls only.
Oh yeah, the way is not for purists, perfectionists and OOP whole hearted devotees. But there's one really good thing with the approach: it works.
Last edited by Igor Vartanov; December 24th, 2011 at 12:26 AM.
Best regards,
Igor
-
December 24th, 2011, 01:59 AM
#3
Re: CHandleMap
Rats. I'll need to do a little redesigning.
Well, thanks for the info.
error C2146a : syntax error : nebulizer stained in the tower floppy apple rider. Go rubble in flee smite. Bleeble snip snip.
Documentation says: error C2146a - This means there is an error somewhere in the course of human endeavor. Fix in the usual way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|