Data Object Handlers

A data object handler allows your application to supply the IDataObject interface for a file type when files are being dragged and dropped or copied and pasted. IDataObject is an important OLE interface that is responsible for transferring and caching data and presentations. IDataObject defines functions that retrieve, store, and enumerate data and that handle data-change notifications. A default IDataObject is available for all file types, so you don't have to implement this interface if you like the default implementation.

Like the drop target handler, only one data object handler is supported at a time. To register a data object handler, you use the DataHandler key in the Registry and give the CLSID value of your extension:

[HKEY_CLASSES_ROOT\SampleType\shellex\DataHandler]
@="{<CLSID value>}"

A data object handler is initialized with the IPersistFile interface and implements the IDataObject interface. Aside from the standard IUnknown member functions, this handler must implement the following functions.

GetData

The GetData member function retrieves the data associated with the given object, in the format that is specified from a designated storage medium. Both the data format (FORMATETC) and the storage medium (STGMEDIUM) are defined in detail in the OLE 2 Help documentation.

GetDataHere

This member function, like GetData, retrieves the data associated with the given object, in the format that is specified from a designated storage medium. In the GetData function, however, the callee provides the storage medium, whereas the caller supplies the storage medium in the GetDataHere function.

QueryGetData

QueryGetData looks at the format of the data and determines whether a call to GetData will succeed.

GetCanonicalFormatEtc

GetCanonicalFormatEtc retrieves a list of the formats supported for the object.

SetData

This member function sets the data in the specified format.

EnumFormatEtc

The EnumFormatEtc member function enumerates the formats that you can use to store data obtained by the GetData function or sent with the SetData function.

DAdvise

DAdvise creates a connection between the data transfer object and an advisory sink. The advisory sink is then informed when the object's data changes.

DUnadvise

The DUnadvise member function deletes the advisory sink connection that the DAdvise function establishes.

EnumDAdvise

The EnumDAdvise member function enumerates the advisory sink connections currently established for an object.

Like the IDropTarget interface, the IDataObject interface is fully explained and referenced in the OLE 2 documentation. If you aren't familiar with drop targets or data objects, however, it's probably not a good idea to think about creating an extension to implement these interfaces.