如何获得给定PIDL的IPortalDeviceContent接口

How to get IPortableDeviceContent interface for given PIDL

本文关键字:IPortalDeviceContent 接口 PIDL 何获得      更新时间:2023-10-16

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

(关于获取IWMDMStorageControl接口,我提出了类似的问题:如何获得给定PIDL的IWMDMStorageControl接口)

我们可以通过以下方式从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文件结构。这不是一个优雅的解决方案,但它是我唯一找到的解决方案。

相关文章:
  • 没有找到相关文章