Share via


Creating Data Handlers

When a file is copied to the clipboard or dragged and dropped, the Shell creates a data object that supports a variety of standard clipboard formats. For files that are members of a file class, you can extend the available clipboard formats by implementing and registering a data handler. When a member of the file class is transferred, the Shell delegates calls to the data object's IDataObject interface to the data handler if one of the custom formats is used.

The general procedures for implementing and registering a Shell extension handler are discussed in Creating Shell Extension Handlers. This document focuses on those aspects of implementation that are specific to data handlers.

  • Registering Data Handlers
  • Implementing Data Handlers

Registering Data Handlers

Data handlers are registered under the file class' HKEY_CLASSES_ROOT\ProgID\shellex\DataHandler subkey. Create a subkey of DataHandler named for the handler, and set the subkey's default value to the string form of the handler's class identifier (CLSID) GUID. For a general discussion of how to register Shell extension handlers, see Creating Shell Extension Handlers.

The following example illustrates registry entries that enable a data handler for an example .myp file class.

HKEY_CLASSES_ROOT

  • .myp

CLSID

{00000000-1111-2222-3333-444444444444}

  • InProcServer32

MyProgram.1

(Default) = MyProgram Application

Shellex

  • DataHandler

Implementing Data Handlers

Like all Shell extension handlers, data handlers are in-process Component Object Model (COM) objects implemented as DLLs. They export two interfaces in addition to IUnknown: IPersistFile and IDataObject.

The Shell initializes the handler through its IPersistFile interface. It uses this interface to request the handler's CLSID and provides it with the file's name. For a general discussion of how to implement Shell extension handlers, including the IPersistFile interface, see Creating Shell Extension Handlers.

Once the data handler is initialized, the Shell delegates calls from the data object to the handler's IDataObject interface if one of the custom formats is used.