title: MFC data forwarding to main thread via PostMessage
body: <p>I have a C++/MFC application I need to restructure. The app used to process most of the data on the main thread, therefore blocking the input, and now I want to change it so, that all GUI updates are done through PostMessage.</p>
  
  <p>Unfortunately, I can't seem to find a good source on how to achieve this goal.</p>
  
  <p>Right now I'm thinking of creating a priority queue, protected with critical section, a worker thread (while(true)) that processes this queue, and PostMessage mechanism that sends pointers to data to main thread.</p>
  
  <p>What scares me with this approach is that PostMessage is not guaranteed to arrive at the main thread at all, so, if I understand correctly, there is a chance of memory leak.</p>
  
  <p>The second problem is that another app can send a custom message to my application, and my application might try to dereference the WPARAM or LPARAM as a pointer thereby causing AV.</p>
  
  <p>Does anyone know what are the best practices for such tasks?</p>
  
  <p>The data can be HTML content for web control, or other content for listboxes, dropdowns, etc.</p>