如何获取给定PIDL的IPortableDeviceContent接口

时间:2012-07-11 13:51:33

标签: c++ windows interface wpd mtp

我使用SHBrowseForFolder()在MTP设备上选择一个文件夹。然后我想从/到那里复制文件。 IPortableDeviceContent接口(来自Windows Portable Devices SDK)似乎合适,但如何从带有PIDL的对象获取它,从SHBrowseForFolder()返回?

(我问过有关获取IWMDMStorageControl接口的类似问题: How to get IWMDMStorageControl interface for given PIDL

1 个答案:

答案 0 :(得分:0)

我们可以通过这种方式从SHBrowseForFolder()中获取与PILD相关联的显示名称:

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]) );
    }
}

然后我们可以解析路径并通过相同的路径遍历MTP文件结构。这不是优雅的解决方案,但它是我找到的唯一一个。