How to get IWMDMStorageControl interface for given PIDL

前端 未结 1 544
醉酒成梦
醉酒成梦 2021-01-26 11:42

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 suitab

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-26 11:57

    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.

    0 讨论(0)
提交回复
热议问题