0

In a previous thread I asked about listing real filenames stored on a Portable Device (e.g. an MTP Digital Camera). Per my answer I can now traverse the file system and display real filenames.

Now I need to enable Copy/Paste for these files, which Windows Explorer allows. After copying a file to the Clipboard I need to paste it onto a real drive, such as C:.

The following code returns whether there's something in the Clipboard to paste. If I copy a regular file in Windows Explorer, I can detect using this code that there's something pasteable for me: hDrop is not NULL. However when a Portable Device file is copied in Windows Explorer, hDrop is NULL. This tells me that it's a "pseudo"-Copy, and Windows Explorer has some kind of internal workaround which doesn't work in external applications. I was hoping there was a GUID of some kind to identify a device's paths, but based on this I see that this may not be the case.

OpenClipboard(NULL);
HDROP hDrop = (HDROP)GetClipboardData(CF_HDROP);
CloseClipboard();
if (hDrop != 0) {
    return true; // Pasteable file(s) exist
}
else {
    return false; // Pasteable file(s) do not exist
}

Because there doesn't seem to be any path support, I also wouldn't be able to use SHFileOperation to copy files. So what would be the solution? Do I need to do a byte-copy of some kind, and manually create a file from the bytes?

2
  • 2
    Run EnumClipboardFormats in a loop to learn which data formats are on the clipboard. Commented Nov 30 at 22:22
  • 2
    For you prev question and answer you could use Shell API instead to enumerate WPD (like here devblogs.microsoft.com/oldnewthing/20150126-00/?p=44833), much simpler. Working with shell items (IShellItem) is easier, you can get them out of an IDataObject (calling OleGetClipboard) using SHCreateShellItemArrayFromDataObject, into using SHCreateDataObject. HDROP is somewhat legacy for generalized shell works, CFSTR_SHELLIDLIST is better (uses PIDLs) (learn.microsoft.com/en-us/windows/win32/shell/…), doesn't need physical file paths Commented Dec 1 at 9:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.