Win32 C++: Get path of Portable Device file to enable Copy/Paste
18:05 30 Nov 2025

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?

winapi