0

I'm using the common file dialog with FOS_PICKFOLDERS to let the user pick a location to save files. If the user selects a library, e.g. Library\Documents then my current code fails at the point where I call IShellItem::GetDisplayName to extract a file system name. If the item were a file then this would succeed and the library's default save location would be used.

What I would like to do is to detect that the shell item is a library, then obtain an IShellLibrary interface, and then query it to find the default save location. Then I would save my files there.

What is the correct way to detect that an IShellItem refers to a Library?

4

2 回答 2

5

用于从 anSHLoadLibraryFromItem()中获取an ,例如:IShellLibraryIShellItem

IShellItem *pItem, *pSave;
IShellLibrary *pLibrary;
...
if (SUCCEEDED(SHLoadLibraryFromItem(pItem, STGM_READWRITE, IID_IShellLibrary, (void**)&pLibrary)))
{
    pLibrary->GetDefaultSaveFolder(DSFT_DETECT, IID_IShellItem, (void**)&pSave);
    pLibrary->Release();
}
else
{
    pSave = pItem;
    pSave->AddRef();
}
...
pSave->GetDisplayName(...);
pSave->Release();
于 2013-05-14T18:02:53.663 回答
1

我发现的唯一方法是使用IShellLibrary::LoadLibraryFromItem此处为 MSDN),您将向其传递一个IShellItem接口。

如果它失败(即HRESULT != S_OK),那么IShellItem它就不是一个库。

所以是这样的:

bool IsLibrary(IShellItem *pItem)
{
    bool bIsLibrary = false;

    IShellLibrary *plib = NULL;
    HRESULT hr = CoCreateInstance(CLSID_ShellLibrary, NULL, CLSCTX_INPROC_SERVER, 
        IID_PPV_ARGS(&plib));
    if (SUCCEEDED(hr))
    {
        hr = plib->LoadLibraryFromItem(pItem, STGM_READ);
        if (SUCCEEDED(hr)) bIsLibrary = true;
        plib->Release();
    }
    return bIsLibrary;
}

我不知道这是否是“正确”的方式,但无论如何它可能有用。

于 2013-05-14T13:20:37.623 回答