SHDoDragDrop function (shlobj_core.h)

Executes a drag-and-drop operation. Supports drag source creation on demand, as well as drag images.

Syntax

SHSTDAPI SHDoDragDrop(
  [in]  HWND        hwnd,
  [in]  IDataObject *pdata,
  [in]  IDropSource *pdsrc,
  [in]  DWORD       dwEffect,
  [out] DWORD       *pdwEffect
);

Parameters

[in] hwnd

Type: HWND

The handle of the window used to obtain the drag image. This value can be NULL. See Remarks for more details.

[in] pdata

Type: IDataObject*

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

[in] pdsrc

Type: IDropSource*

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

As of Windows Vista, if this value is NULL, the Shell creates a drop source object for you.

[in] dwEffect

Type: DWORD

The effects that the source allows in the drag-and-drop operation. The most significant effect is whether the drag-and-drop operation permits a move. For a list of possible values, see DROPEFFECT.

[out] pdwEffect

Type: DWORD*

A pointer to a value that indicates how the drag-and-drop operation affected the source data. The pdwEffect parameter is set only if the operation is not canceled. For a list of possible values, see DROPEFFECT.

Return value

Type: HRESULT

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

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

Remarks

As of Windows Vista, if a drag image is not already stored in the data object pdtobj and a drag image cannot be obtained from the window specified by hwnd, the Shell provides a generic drag image. A drag image can fail to be obtained from the specified window either because hwnd is NULL or the specified window does not support the DI_GETDRAGIMAGE message.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header shlobj_core.h (include Shlobj.h)
Library Shell32.lib
DLL Shell32.dll (version 6.0 or later)
API set ext-ms-win-shell-shell32-l1-2-1 (introduced in Windows 10, version 10.0.10240)