如何取消正在进行的ISearchFolderItemFactory查询

时间:2013-12-16 23:48:09

标签: c++ windows windows-shell

使用ISearchFolderItemFactory,我发现行pEnum->Next(1, &pChildItem, &ulFetched);在搜索下一个结果时可能会花费无约束的时间。如果查询没有结果,并且搜索范围也未编入索引,则这尤其痛苦。有没有办法取消搜索,或以更异步的方式获取搜索结果?我删除了错误处理和清理以简洁。

ISearchFolderItemFactory* folderSearch = nullptr;
hr = ::CoCreateInstance(CLSID_SearchFolderItemFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&folderSearch));
if (FAILED(hr)) { ... }

hr = folderSearch->SetScope(scopedItemArray);
if (FAILED(hr)) { ... }

hr = folderSearch->SetCondition(pc);
if (FAILED(hr)) { ... }

IShellItem* shellItem = nullptr;
hr = folderSearch->GetShellItem(IID_PPV_ARGS(&shellItem));
if (FAILED(hr)) { ... }

IEnumShellItems* pEnum = nullptr;
hr = shellItem->BindToHandler(nullptr, BHID_EnumItems, IID_PPV_ARGS(&pEnum));
if (FAILED(hr)) { ... }

IShellItem* pChildItem = nullptr;
ULONG ulFetched = 0;
do {
    hr = pEnum->Next(1, &pChildItem, &ulFetched);
    if (FAILED(hr)) break;
    if (ulFetched != 0) {
        LPWSTR szChildName = nullptr;
        pChildItem->GetDisplayName(SIGDN_FILESYSPATH, &szChildName);
        wprintf(L"Obtained %s\n", szChildName);
        CoTaskMemFree(szChildName);
        pChildItem->Release();
    }
} while (hr != S_FALSE);

0 个答案:

没有答案