0

I use SHBrowseForFolder() to select a folder on MTP device. Then I want to copy file from/to there. IWMDMStorageControl interface (from Windows Media Format 11 SDK) seems suitable, but how to get it for the object with PIDL, returned from SHBrowseForFolder()?

(I asked similar question about obtaining IWMDMStorageControl interface: How to get IPortableDeviceContent interface for given PIDL)

Community
  • 1
  • 1
ggurov
  • 1,496
  • 2
  • 15
  • 21
  • The starting point is entirely wrong, MTP does *not* give access to the file system. http://www.differencebetween.net/technology/difference-between-mtp-and-msc/ – Hans Passant Jul 11 '12 at 17:22
  • 1
    I know, thats why I ask about IWMDMStorageControl interface, not for regular FileCopy. I need only to know how to make correspondence between the user choise through SHBrowseForFolder and WMDM or WPD interfaces/methods. In Win.Explorer or with SHBrowseForFolder the user sees regular tree structure on MTP device (Samsung tablet in my case) just like disk drives. How one can choose folder there if not with SHBrowseForFolder? – ggurov Jul 11 '12 at 19:40
  • Actually it is real file system on these devices. The whole problem is that they dont offer usb drive mode but only MTP or PTP. – ggurov Jul 11 '12 at 19:48
  • Did you find a way to at least retreive the displayed name associated with the PILD returned by SHBrowseForFolder() for the selected MTP folder ? – Regis St-Gelais Jan 18 '13 at 16:16
  • Yes, I will place the code as answer. – ggurov Jan 19 '13 at 19:57

1 Answers1

0

We can get the displayed name, associated with the PILD from SHBrowseForFolder() in this way:

TCHAR DisplayName[MAX_PATH]; // we will get it here
LPITEMIDLIST pidlSelected = SHBrowseForFolder( &bi );
if ( pidlSelected && ! SHGetPathFromIDList(pidlSelected, DisplayName) )
{ // it is media device
    IShellFolder *psfParent;
    LPCITEMIDLIST pidlRelative;
    STRRET str;
    HRESULT hres = SHBindToParent(pidlSelected, IID_IShellFolder, (void**)&psfParent, &pidlRelative);
    if (SUCCEEDED(hres))
    {
        psfParent->GetDisplayNameOf( pidlRelative, SHGDN_FORADDRESSBAR, &str );
        psfParent->Release();
        StrRetToBuf( &str, pidlSelected, DisplayName, sizeof(DisplayName)/sizeof(DisplayName[0]) );
    }
}

Then we can parse the path and traverse through MTP file structure by the same path. It is not elegant solution, but it is the only one which I found.

ggurov
  • 1,496
  • 2
  • 15
  • 21