CloseClipboard

The CloseClipboard function closes the current session on the clipboard, enabling other applications to manipulate the clipboard. Clipboard operations are performed on a per-thread basis.

BOOL CloseClipboard(VOID);

Parameters

This function has no parameters.

Return value

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

An application must call OpenClipboard before calling any other clipboard function on the clipboard. An application calls CloseClipboard after it has completed all the clipboard operations.

If an application calls CloseClipboard without first calling OpenClipboard, the return value is zero.

There is a one-to-one correspondence between calls to OpenClipboard and CloseClipboard. For every call to OpenClipboard, there must be a corresponding call to CloseClipboard.

Important: Be sure to close the clipboard after each use. Failing to close the clipboard can prevent other applications from accessing it.

Requirements

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

See also

Example

The following code example closes the clipboard. It assumes that the clipboard has already been opened and data has been placed on it.


// Assume clipboard has been opened and data is handled
if (!CloseClipboard()) {
    // Handle error
    MessageBox(NULL, TEXT("Failed to close clipboard!"), TEXT("Error"), MB_OK);
} else {
    // Clipboard successfully closed
}