INFO: Reasons for Failure of Clipboard Functions

ID: Q92530


The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK)
  • Microsoft Windows Software Development Kit (SDK) 3.1
  • Microsoft Windows 2000


SUMMARY

The following clipboard functions:

OpenClipboard()
CloseClipboard()
EmptyClipboard()
GetClipboardData()
SetClipboardData()
EnumClipboardFormats()
SetClipboardViewer()
ChangeClipboardChain()
GetOpenClipboardWindow()
GetClipboardOwner()
can fail for several reasons. Different functions return different values to indicate failure. Read the documentation for information about each function. This article combines the causes of failure for all functions and provides a resolution or explanation. In the More Information section, a list of affected functions follows each cause. The causes are:
  1. The clipboard is not opened by any application.


  2. The current application does not have the clipboard open.


  3. The current application does not own the clipboard.


  4. User's data segment is full.


  5. Insufficient global memory.


  6. The specified clipboard format is not supported.


  7. The application that set the clipboard data placed a corrupt or invalid metafile in the clipboard.


  8. An application is attempting to open an already open clipboard. The debug mode of Windows 3.1 will send the "Clipboard already open" message.


  9. The application that opened the clipboard used NULL as the window handle.



MORE INFORMATION

Cause 1: The clipboard is not opened by any application.

Resolution 1: Open the clipboard using OpenClipboard(). If a DLL needs to open the clipboard, it may pass hwnd = NULL to OpenClipboard().

Explanation 1: An application cannot copy data (using SetClipboardData()) when no application has the clipboard currently open.

Affected Functions: SetClipboardData().

Cause 2: The current application does not have the clipboard open.

Resolution 2: Open the clipboard using OpenClipboard(). If a DLL needs to open the clipboard, it may pass hwnd = NULL to OpenClipboard().

Explanation 2: An application cannot empty or close the clipboard without first opening it.

Affected Functions: EmptyClipboard(), CloseClipboard().

Cause 3: The current application does not own the clipboard.

Resolution 3: Open the clipboard and get ownership by emptying it.

Explanation 3: An application cannot enumerate the clipboard formats without owning it.

Affected Functions: EnumClipboardFormats().

Cause 4: User's data segment is full.

Explanation 4: There should be space available in User's data segment to store internal data structures when SetClipboardData() is called.

Affected Function: SetClipboardData().

Cause 5: Insufficient global memory.

Explanation 5: If the clipboard has data in either the CF_TEXT or CF_OEMTEXT format and if GetClipboardData() requests text in the unavailable format, then Windows will perform the conversion. The converted text must be stored in global memory.

Affected Function: GetClipboardData().

Cause 6: The specified clipboard format is not supported.

Resolution 6: Use IsClipboardFormatAvailable() to check whether the specified format is available on the clipboard.

Affected Function: GetClipboardData().

Cause 7: The application that set the clipboard data placed a corrupt or invalid metafile in the clipboard.

Resolution 7: There are no functions to tell whether a given metafile is corrupt or invalid. Try playing the metafile and see if the metafile plays as expected.

Affected Function: SetClipboardData().

Cause 8: Application is attempting to open an already open clipboard. The debug mode of Windows 3.1 will send the "Clipboard already open" message.

Explanation 8: The clipboard must be closed by the application that opened it, before other applications can open it.

Affected Functions: OpenClipboard().

Cause 9: The application that opened the clipboard used NULL as the window handle.

Explanation 9: An application can call OpenClipboard(NULL) to successfully open a clipboard. The side effects are that subsequent calls to GetClipboardOwner() and GetOpenClipboardWindow() return NULL. An application can also call SetClipboardViewer(NULL) successfully. However, there is no reason why this should be allowed, and it is currently reported as a bug. The side effects are that subsequent calls to GetClipboardViewer() and ChangeClipboardChain() return NULL. NULL from these functions does not necessarily imply that they failed.

Affected Functions: GetClipboardOwner(), GetOpenClipboardWindow(), GetClipboardViewer(), ChangeClipboardChain().

Additional query words: GetClipboardFormatName RegisterClipboardFormat

Keywords : kbClipboard kbNTOS kbWinOS2000 kbSDKWin32 kbGrpUser kbWinOS
Version : WINDOWS:3.1
Platform : WINDOWS
Issue type : kbinfo


Last Reviewed: January 26, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.