title: who releases handle in SetClipboardData(CF_BITMAP, HBITMAP)?
body: <p>My understanding is that in general when you add a handle to the clipboard, the clipboard then owns the handle and you are not responsible for deleting it, and you should not delete it. This is what it says here: <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms649051%28v=vs.85%29.aspx?f=255&amp;MSPPError=-2147217396" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/ms649051%28v=vs.85%29.aspx?f=255&amp;MSPPError=-2147217396</a></p>
  
  <blockquote>
    <p>If SetClipboardData succeeds, the system owns the object identified by
    the hMem parameter. The application may not write to or free the data
    once ownership has been transferred to the system, but it can lock and
    read from the data until the CloseClipboard function is called. (The
    memory must be unlocked before the Clipboard is closed.) If the hMem
    parameter identifies a memory object, the object must have been
    allocated using the function with the GMEM_MOVEABLE flag.</p>
  </blockquote>
  
  <p>And indeed I see lots of examples where people call GlobalAlloc(), put some text in the global handle, call SetClipboardData(), and then don't free the global handle, because the clipboard owns it.</p>
  
  <p>But in the case of HBITMAP data, added via <code>SetClipboardData(CF_BITMAP, hBitmap)</code>, I see lots of examples like these:</p>
  
  <p><a href="https://stackoverflow.com/a/7292773/384670">https://stackoverflow.com/a/7292773/384670</a></p>
  
  <p><a href="https://stackoverflow.com/a/28248531/384670">https://stackoverflow.com/a/28248531/384670</a></p>
  
  <p>In these cases, the code <em>does</em> delete the HBITMAP after adding it to the clipboard.</p>
  
  <p>Is there a difference between an HBITMAP handle and a GlobalAlloc() handle with respect to the clipboard? Is there something special about the CF_BITMAP that's an exception to the rule, and the clipboard <em>copies</em> the handle instead of <em>owns</em> it? Can you point me to official (MSDN) documentation that explains the difference?</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Here is one more example that involves both types of handle in one article: <a href="http://www.codeproject.com/Articles/42/All-you-ever-wanted-to-know-about-the-Clipboard" rel="nofollow noreferrer">http://www.codeproject.com/Articles/42/All-you-ever-wanted-to-know-about-the-Clipboard</a></p>
  
  <p>Notice that in the case of the bitmap the author specifically says:</p>
  
  <blockquote>
    <p>//copy has been made on clipboard so we can delete</p>
  </blockquote>