title: Windows API - Clipboard - GlobalLock - use or not to use?
body: <p>I've seen practise that if you are going to get contents from the Windows clipboard by <code>GetClipboardData()</code>, the <code>GlobalLock()</code> function is called on handle returned by <code>GetClipboardData()</code> first - before retrieving the data (e.g.convert&amp;store).</p>
  
  <p>However I found out that (at least in C++11) I can get the same data without the locking...</p>
  
  <p>So there are 3 sub questions...</p>
  
  <ol>
  <li>How is this possible?</li>
  <li>Is it safe in one-thread app ran only "single"?</li>
  <li>Is it safe in one-thread app ran simultaneously multiple times?</li>
  </ol>
  
  <p>...resulting in one BIG question - use or not to use <code>GlobalLock()</code> <strong>&amp;&amp; when?</strong></p>
  
  <p><em>PS: Of course after each potencial <code>GlobalLock()</code> you should call <code>GlobalUnlock()</code></em></p>
  
  <p>This is simplyfied part where I retrieve the data:</p>
  
  <pre><code>HANDLE clipboardHandle;
  string clipboardContents = "";
  clipboardHandle = GetClipboardData( CF_OEMTEXT );
  clipboardContents = (string)static_cast&lt;char*&gt;( clipboardHandle );
  cout &lt;&lt; "Clipboard data:" &lt;&lt; clipboardContents; //prints out fine
  </code></pre>