How to get IPortableDeviceContent interface for given PIDL

纵饮孤独 提交于 2019-12-11 14:22:05

问题


I use SHBrowseForFolder() to select a folder on MTP device. Then I want to copy file from/to there. IPortableDeviceContent interface (from Windows Portable Devices 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 IWMDMStorageControl interface for given PIDL)


回答1:


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.



来源:https://stackoverflow.com/questions/11434180/how-to-get-iportabledevicecontent-interface-for-given-pidl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!