title: Which are the safe way to send CString through PostMessage from thread
body: <p>What is the safe / best way to send a <code>CString</code> through <code>PostMessage</code>, from a thread ?
  To create <code>CString</code> on heap and clean up when the receiver get this <code>CString</code> ?</p>
  
  <p><strong>Solution 1:</strong> In  thread:</p>
  
  <pre><code>CString* pError = new CString(_T("Unknown error"));
  ::PostMessage(...(LPARAM)pError);
  </code></pre>
  
  <p>and in main thread, somewhere in GUI:</p>
  
  <pre><code>CString* pError = (CString*)lParam;
  GetDocument()-&gt;DoSomething(*pError);
  delete pError;
  </code></pre>
  
  <p><strong>Solution 2:</strong>
  Or, to keep <code>CString</code> object as member variable inside of <code>CThread</code> class ?</p>
  
  <pre><code>class CPlanThread : public CThread [: public CObject]
  {
  public:
  DECLARE_DYNAMIC(CPlanThread)
  
  ...
  protected:
  CString* m_pMessage;
  
  };
  </code></pre>
  
  <p>and </p>
  
  <pre><code>CPlanThread::CPlanThread()
  :m_pMessage(NULL)
  {
  m_pMessage = new CString(_T(""));
  }
  
  CPlanThread::~CPlanThread()
  {
  if(NULL != m_pMessage)
      delete m_pMessage;
  }
  </code></pre>
  
  <p>and somewhere in thread:</p>
  
  <pre><code>::PostMessage(m_hWndMain, WMU_NOTIFYTHREAD, 0, (LPARAM)m_pMessage);
  </code></pre>
  
  <p>and in main thread, somewhere in GUI:</p>
  
  <pre><code>CString* pError = (CString*)lParam;
  GetDocument()-&gt;DoSomething(*pError);
  </code></pre>
  
  <p>Both of the above solutions are safe ? Kindly thank you for any explanation.</p>