DoDragDrop function (ole2.h)

Carries out an OLE drag and drop operation.

Note  You must call OleInitialize before calling this function.


  [in]  LPDATAOBJECT pDataObj,
  [in]  LPDROPSOURCE pDropSource,
  [in]  DWORD        dwOKEffects,
  [out] LPDWORD      pdwEffect


[in] pDataObj

Pointer to the IDataObject interface on a data object that contains the data being dragged.

[in] pDropSource

Pointer to an implementation of the IDropSource interface, which is used to communicate with the source during the drag operation.

[in] dwOKEffects

Effects the source allows in the OLE drag-and-drop operation. Most significant is whether it permits a move. The dwOKEffect and pdwEffect parameters obtain values from the DROPEFFECT enumeration. For a list of values, see DROPEFFECT.

[out] pdwEffect

Pointer to a value that indicates how the OLE drag-and-drop operation affected the source data. The pdwEffect parameter is set only if the operation is not canceled.

Return value

This function returns S_OK on success. Other possible values include the following.

Return code Description
The OLE drag-and-drop operation was successful.
The OLE drag-and-drop operation was canceled.
Unexpected error occurred.


If you are developing an application that can act as a data source for an OLE drag-and-drop operation, you must call DoDragDrop when you detect that the user has started an OLE drag-and-drop operation.

The DoDragDrop function enters a loop in which it calls various methods in the IDropSource and IDropTarget interfaces. (For a successful drag-and-drop operation, the application acting as the data source must also implement IDropSource, while the target application must implement IDropTarget.)

  1. The DoDragDrop function determines the window under the current cursor location. It then checks to see if this window is a valid drop target.
  2. If the window is a valid drop target, DoDragDrop calls IDropTarget::DragEnter. This method supplies an effect code indicating what would happen if the drop actually occurred. For a list of valid drop effects, see the DROPEFFECT enumeration.
  3. DoDragDrop calls IDropSource::GiveFeedback with the effect code so that the drop source interface can provide appropriate visual feedback to the user. The pDropSource pointer passed into DoDragDrop specifies the appropriate IDropSource interface.
  4. DoDragDrop tracks mouse cursor movements and changes in the keyboard or mouse button state.
  5. If there is a change in the keyboard or mouse button state, DoDragDrop calls IDropSource::QueryContinueDrag and determines whether to continue the drag, to drop the data, or to cancel the operation based on the return value.
    • If the return value is S_OK, DoDragDrop first calls IDropTarget::DragOver to continue the operation. This method returns a new effect value and DoDragDrop then calls IDropSource::GiveFeedback with the new effect so appropriate visual feedback can be set. For a list of valid drop effects, see the DROPEFFECT enumeration. IDropTarget::DragOver and IDropSource::GiveFeedback are paired so that as the mouse moves across the drop target, the user is given the most up-to-date feedback on the mouse's position.
    • If the return value is DRAGDROP_S_DROP, DoDragDrop calls IDropTarget::Drop. The DoDragDrop function returns the last effect code to the source, so the source application can perform the appropriate operation on the source data, for example, cut the data if the operation was a move.
    • If the return value is DRAGDROP_S_CANCEL, the DoDragDrop function calls IDropTarget::DragLeave.
DoDragDrop does not support invoking drag and drop support when you handle touch or pen input.

To support touch or pen input, do not call DoDragDrop from your touch handler. Instead, call DoDragDrop from your handler for those mouse messages that the system synthesizes upon touch input.

The application can identify synthesized messages by calling the GetMessageExtraInfo function. For more information about using GetMessageExtraInfo to distinguish between mouse input and Windows Touch input, see Troubleshooting Applications.


Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header ole2.h
Library Ole32.lib
DLL Ole32.dll

See also