Search code examples
cwindowswinapidrag-and-dropole

OLE Drag and Drop: use wide char or not?


Implementing IDropSource requires to create and fill a DROPFILES structure. The fWide member specifies whether a wide string should be used or not.

Since I'm drag-dropping files to the Windows file system, when should I use wide char? I know that dragging a file from the File Explorer yields fWide==TRUE, at least on my Windows 10 (multilanguage). However this might be different on other Windows flavors. How can I determine which to use?

In the opposite direction, when should I expect fWide==TRUE when implementing IDropTarget?


Solution

  • Wide (Unicode) is guaranteed to store the string correctly, narrow strings ("ANSI") are not.

    When you receive this data you should support both formats. DragQueryFileW will do this for you.

    When you manually construct this structure yourself you should generally use wide strings.

    There are 3 possible receivers of your data:

    • NT based versions of Windows (anything released in the last 20 years). The native string type is wide but the narrow string is also supported.

    • Windows 95/98/ME uses narrow strings as their native string type, don't expect wide strings to be supported in most places. It is extremely unlikely that you care about these Windows versions.

    • Third-party software. It is impossible to know ahead of time what they support. You just have to hope for the best and use wide strings.

    Ideally your data object also contains the CFSTR_SHELLIDLIST format, this should sidestep most string issues.