title: Is CWnd::GetSafeHwnd() and CWnd::m_hWnd ThreadSafe?
body: <p>I am facing numerous crashes on a application which is heavily multi-threaded.</p>
  
  <p>Reading these MSDN <a href="http://msdn.microsoft.com/fr-fr/library/h14y172e.aspx" rel="nofollow noreferrer">page</a>, <a href="http://msdn.microsoft.com/fr-fr/library/c251x6s1.aspx" rel="nofollow noreferrer">technical note</a> and <a href="http://msdn.microsoft.com/fr-fr/library/ms686749.aspx" rel="nofollow noreferrer">this article on TLS</a>, I have understood that <code>CWnd</code> objects are mapped to HWND in the Thread Local Storgae (TLS, which is a thread dependendent memory access).</p>
  
  <p>I was going to decouple everything that looks like CWnd thread-remote access, and transform it into <code>HWND</code> references and then use <code>::PostMessage</code> as communication port.</p>
  
  <p>But one of my colleagues really insisted that I just keep the <code>CWnd*</code> in the foreigner threads, adopt the <code>::PostMessage</code> policy ok, but use <code>CWnd::GetSafeHwnd()</code> or the <code>pMyCWnd-&gt;m_hWnd</code> in the foreign threads so as to recover the native <code>HWND</code>.</p>
  
  <p>I have been arguing that <strong>nowhere</strong> I have seen that the <code>GetSafeHwnd()</code> is threadsafe, and that the <code>CWnd</code> objet being in the TLS, it's value in another thread is different.</p>
  
  <p>I am wrong ? The MSDN is clearly using the term <strong>Unexpected results</strong>.</p>
  
  <p>What's your point of view, about calling <code>CWnd::GetSafehwnd()</code> or <code>pMyCWnd-&gt;m_hWnd</code> in outer threads from the creator thread ?</p>
  
  <p>Do you have any MSDN documentation that states that this is safe or not.</p>