Memory and the Clipboard

A memory object that is to be placed on the clipboard should be allocated by using the GlobalAlloc function with the GMEM_DDESHARE and GMEM_MOVEABLE flags.

Once a memory object is placed on the clipboard, ownership of that memory handle is transferred to the system. When the clipboard is emptied and the memory object has one of the following clipboard formats, the system frees the memory object by calling the indicated Win32 function:

Function called to free object Clipboard format
DeleteMetaFile CF_DSPENHMETAFILE
  CF_DSPMETAFILEPICT
  CF_ENHMETAFILE
  CF_METAFILEPICT
DeleteObject CF_BITMAP
  CF_DSPBITMAP
  CF_PALETTE
GlobalFree CF_DIB
  CF_DSPTEXT
  CF_OEMTEXT
  CF_TEXT
  CF_UNICODETEXT

When the clipboard is emptied of a memory object whose clipboard format is not shown in the preceding list, the application itself must free the memory object.