Microsoft KB Archive/24252

{|
 * width="100%"|

INFO: SetClipboardData and CF_PRIVATEFIRST

 * }

Q24252

-

The information in this article applies to:


 * Microsoft Windows Software Development Kit (SDK)
 * Microsoft Win32 Software Development Kit (SDK)

-

SUMMARY
The documentation for SetClipboardData states that CF_PRIVATEFIRST can be used to put private data formats on the clipboard. It also states that data of this format is not automatically deleted. However, that is apparently not true. That is, the data is removed automatically when the clipboard is emptied (sending a WM_DESTROYCLIPBOARD message) and the new item is set into the clipboard. The old item is shown; however, the handle now is invalid because GlobalFree is called on it.

MORE INFORMATION
GlobalFree was not called on this handle. If you try to use the other handle to this memory, you will find that the one you initially received from GlobalAlloc is still valid. Only the clipboard handle has been invalidated by the call to EmptyClipboard.

The documentation states that "Data handles associated (with CF_PRIVATEFIRST) will not be freed automatically." This statement refers to the memory associated with that data handle. When SetClipboardData is called under standard data types, it frees the block of memory identified by hMem. This is not the case for CF_PRIVATEFIRST. Applications that post CF_PRIVATEFIRST items on the clipboard are responsible for the memory block containing those items.

This is not intended to imply that items placed on the clipboard will remain on the clipboard if they are CF_PRIVATEFIRST. When a call is made to EmptyClipboard, all objects will be removed.

Additional query words:

Keywords : kbClipboard kbOSWinNT kbOSWin2000 kbSDKWin32 kbGrpDSUser kbOSWin

Issue type : kbinfo

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch kbWinSDKSearch