Your messages will get there. I'm not sure why you think PostMessage does not guarantee work - it is. (EDIT: Assuming PostMessage () returns TRUE! Check return codes!)
You want to avoid using a queue to transfer data between threads. Any queue that both threads access must be secured. Adding hard locks on both sides will serialize your application.
Instead, create a data structure on the heap using new , which contains your data, and then tell another thread: "I have data for you, and here it is." The receiving stream then takes responsibility for this data pointer and is responsible for delete for its use. So there are no hard locks.
Now the only trick is to figure out the “tell a different topic” part, but it's easy too.
If you are sending data from a workflow to the main thread, just use PostMessage() :
worker_thread_proc() {
... the main thread processes this and then deletes the data:
MainWnd::OnYouHaveData(WPARAM wp, LPARAM) { std::auto_ptr<MyData> data(reinterpret_cast<MyData*>(wp)); my_widget->set_text(data->some_value_);
If you are worried that custom messages from external applications are bumping into you, you can force Windows to give you a unique message identifier using RegisterWindowsMessage () - your only problem here is to choose the right name for your message.
If you send data from the main thread to the workflow, you can do the same as above, except using PostMessage() to send data on the wall, you can use either QueueUserAPC () (make sure your work thead is in standby - read comments in related docs) or PostThreadMessage () .
EDIT:
In your comments on the OP, I now understand why you are worried that PostMessage () is not working.
Yes, there is a hard limit on the size of the Windows message queue. By default, only 4,000 messages can be queued. (registry settings can configure this up to 10,000).
If the queue is full, any call to PostMessage() will end with an error code. When you check GetLastError () (I don’t remember which error code it is returning right now), it will be clear that the message queue is full.
Doesn't sound like a mother chicken, but you really need to check your return values from API calls. But besides this, if you are working in a thread of a message queue, I would say that your application will break anyway. When the queue is full, your application will not be able to breathe. The screen will not draw, any processing that you do will be out of date, and all kinds of bad things happen. If this is the situation you are in, you may need to see why.