How to Create 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 of a specific file type, you can extend the available clipboard formats by implementing and registering a data handler. When a file of the file type 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.

Instructions

Step 1: 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 class identifier (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.

Step 2: Registering Data Handlers

Data handlers are registered under the file type's ProgID subkey as shown here: HKEY_CLASSES_ROOT\ProgID\shellex\DataHandler

Create a subkey named for the handler under DataHandler and set the default value of that handler's subkey to the string form of the handler's 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 type.

HKEY_CLASSES_ROOT
   .myp
      (Default) = MyProgram.1
   CLSID
      {00000000-1111-2222-3333-444444444444}
         InProcServer32
            (Default) = C:\MyDir\MyCommand.dll
            ThreadingModel = Apartment
   MyProgram.1
      (Default) = MyProgram Application
      Shellex
         DataHandler
            (Default) = {00000000-1111-2222-3333-444444444444}

Related topics

Creating Shell Extension Handlers
IPersistFile
IDataObject

 

 

Community Additions

ADD
Show:
© 2015 Microsoft