OleGetClipboard  3GWZ93

Retrieves a data object that you can use to access the contents of the clipboard.

WINOLEAPI OleGetClipboard(

    IDataObject ** ppDataObj

//Indirect pointer to the interface on the data object

   );

 

 

Parameter

ppDataObj

[out] Indirect pointer to the IDataObject interface on the clipboard data object.

 

Return Values

This function supports the standard return values E_INVALIDARG and E_OUTOFMEMORY, as well as the following:

S_OK

The data object was successfully retrieved.

CLIPBRD_E_CANT_CLOSE

The Windows CloseClipboard function used within OleGetClipboard failed.

CLIPBRD_E_CANT_OPEN

The Windows OpenClipboard function used with OleGetClipboard failed.

 

Remarks

If you are writing an application that can accept data from the clipboard, call the OleGetClipboard function to get a pointer to the IDataObject interface that you can use to retrieve the contents of the clipboard.

OleGetClipboard handles three cases:

  1.  The application that placed data on the clipboard with the OleSetClipboard21ELJF5 function is still running.

  2.  The application that placed data on the clipboard with the OleSetClipboard function has subsequently called the OleFlushClipboardHDB2_Z function.

  3.  There is data from a non-OLE application on the clipboard.

 

In the first case, the clipboard data object returned by OleGetClipboard may forward calls as necessary to the original data object placed on the clipboard and, thus, can potentially make RPC calls.

In the second case, OLE creates a default data object and returns it to the user. Because the data on the Clipboard originated from an OleSetClipboard21ELJF5 call, the OLE-provided data object contains more accurate information about the type of data on the Clipboard. In particular, the original medium (TYMED1QNCE4N) on which the data was offered is known. Thus, if a data-source application offers a particular clipboard format, for example cfFOO, on a storage object and calls the OleFlushClipboardHDB2_Z function, the storage object is copied into memory and the hglobal memory handle is put on the Clipboard. Then, when the OleGetClipboard function creates its default data object, the hglobal from the clipboard again becomes an IStorage object. Furthermore, the FORMATETC8CSQ18 enumerator and the IDataObject::QueryGetData31KJZ6I method would all correctly indicate that the original clipboard format (cfFOO) is again available on a TYMED_ISTORAGE.

In the third case, OLE still creates a default data object, but there is no special information about the data in the Clipboard formats (particularly for application-defined Clipboard formats). Thus, if an hGlobal-based storage medium were put on the Clipboard directly by a call to the SetClipboardData function, the FORMATETC enumerator and the IDataObject::QueryGetData method would not indicate that the data was available on a storage medium. A call to the IDataObject::GetData81EL5_ method for TYMED_ISTORAGE would succeed, however. Because of these limitations, it is strongly recommended that OLE-aware applications interact with the Clipboard using the OLE Clipboard functions.

The clipboard data object created by the OleGetClipboard function has a fairly extensive IDataObject implementation. The OLE-provided data object can convert OLE 1 clipboard format data into the representation expected by an OLE 2 caller. Also, any structured data is available on any structured or flat medium, and any flat data is available on any flat medium. However, GDI objects (such as metafiles and bitmaps) are only available on their respective mediums.

Note that the tymed member of the FORMATETC structure used in the FORMATETC enumerator contains the union of supported mediums. Applications looking for specific information (such as whether CF_TEXT is available on TYMED_HGLOBAL) should do the appropriate bit masking when checking this value.

If you call the OleGetClipboard function, you should only hold on to the returned IDataObjectZHWNNR for a very short time. It consumes resources in the application that offered it.

See Also

OleSetClipboard