I have a window with a listbox that displays some progress messages from a thread that is running. The thread basically formats the text into a buffer and then calls PostMessage(). Most of the time this works ok but sometimes the text gets garbled.
In reading the MSDN I located the following:
If you send a message in the range below WM_USER to the asynchronous message functions (PostMessage, SendNotifyMessage, and SendMessageCallback), its message parameters cannot include pointers. Otherwise, the operation will fail. The functions will return before the receiving thread has had a chance to process the message and the sender will free the memory before it is used.
I suspect this is my issue.
Question: what's the best way to avoid this problem? My thread has no clue when Windows processes the message and grabs the stuff in the buffer. I can't use SendMessage because the thread can't wait around all day.
My thought is that I need to implement some sort of a queue in another thread that will accept these calls to output text to the window asynchronously, store the text in the queue, call SendMesasge, then remove the text from the queue. But that seems (to me at least) to be an overly complicated solution to what I think should be a fairly common problem.
Thanks in advance...