GetClipboardData Function

user32.dll

Syntax

HANDLE GetClipboardData(UINT uFormat);

Parameters

Parameter Description
uFormat The format of the clipboard data to retrieve. This parameter can be one of the standard clipboard format values or a custom format that has been registered by the RegisterClipboardFormat function. Common values include:
  • CF_BITMAP: A handle to a bitmap.
  • CF_DIB: A handle to a device-independent bitmap (DIB) section or memory object.
  • CF_HDROP: A handle to a list of files.
  • CF_OEMTEXT: Text in the OEM character set.
  • CF_TEXT: Text in the ANSI character set.
  • CF_UNICODETEXT: Text in the Unicode character set.
  • CF_ENHMETAFILE: A handle to an enhanced metafile.

Return Value

If the function succeeds, the return value is a handle to the clipboard data in the specified format. If the function fails, the return value is NULL.

To get extended error information, call GetLastError.

Remarks

Before calling GetClipboardData, you must open the clipboard by calling the OpenClipboard function. When you are finished retrieving data from the clipboard, you must close the clipboard by calling the CloseClipboard function.

The handle returned by GetClipboardData is owned by the system and should not be freed. It is valid only until the contents of the clipboard are changed or the clipboard is closed.

If the clipboard is empty or if the data is not available in the specified format, GetClipboardData returns NULL.

For text formats, the data is null-terminated.

You should not call GetClipboardData in a loop. Call it once for each format you want to retrieve.

Note: Applications are responsible for calling GlobalFree on the memory object returned by GetClipboardData if the data is in a format that requires manual freeing (e.g., CF_OWNERDISPLAY). However, for most standard formats, the system manages the memory.

Requirements

Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header winuser.h (include windows.h)
Library User32.lib
DLL User32.dll

See Also