Click to See Complete Forum and Search --> : Process User defined thread message?


tangjun
July 20th, 2007, 12:21 AM
How to process the user defined thread message that was sent by another thread in the unmanaged code?

The worker thread is written with unmanaged c++ (MFC) and called PostThreadMessage() to send the user defined messages, now I need to catch that message on the c# or managed wrapper side, how do I do that? Any example?

Krishnaa
July 20th, 2007, 03:09 AM
You willl need to add ON_MESSAGE (http://msdn2.microsoft.com/en-us/library/k35k2bfs(VS.80).aspx) entries on message maps for those messages along with the handler funciton.

tangjun
July 20th, 2007, 09:38 AM
You willl need to add ON_MESSAGE (http://msdn2.microsoft.com/en-us/library/k35k2bfs(VS.80).aspx) entries on message maps for those messages along with the handler funciton.


That's how I do it in MFC. Is there any difference to do it in c++/CLI?

Krishnaa
July 20th, 2007, 10:07 AM
That's how I do it in MFC. Is there any difference to do it in c++/CLI?

No.

tangjun
July 20th, 2007, 10:29 AM
No.


can you post some sample code please?

The messages are thread message, not window message, so I need to create a thread to accept them and I need to customize that thread, while System::Threading::Thread is sealed.

tangjun
July 24th, 2007, 03:34 PM
You willl need to add ON_MESSAGE (http://msdn2.microsoft.com/en-us/library/k35k2bfs(VS.80).aspx) entries on message maps for those messages along with the handler funciton.


You are probablly confused with the managed/unmanaged part in this issue, I would be surprised if there is also ON_MESSAGE macro in c++/CLI

Krishnaa
July 26th, 2007, 10:10 AM
Well, the thread is written in unmanaged (and MFC) code, where you need to catch the messages first, then you can throw them to managed code anyway you want.