我可以在简单的情况下成功地使用SHOpenFolderandSelectItems()。代码看起来类似于以下内容:
ITEMIDLIST *idl = ILCreateFromPath(L"C:\\testing\\example.txt");
SHOpenFolderAndSelectItems(idl, 0, 0, 0);
ILFree(idl);现在我要做的是打开一个文件夹,并在其中选择多个文件。但我对SHOpenFolderAndSelectItems()的期望感到困惑。简化了,这就是我想要做的:
ITEMIDLIST *folder = ILCreateFromPath(L"C:\\testing\\");
std::vector<ITEMIDLIST*> v;
v.push_back( ILCreateFromPath(L"C:\\testing\\test1.txt");
v.push_back( ILCreateFromPath(L"C:\\testing\\test2.txt");
v.push_back( ILCreateFromPath(L"C:\\testing\\test3.txt");
SHOpenFolderAndSelectItems(folder, v.size(), v.data(), 0);
for (auto idl : v)
{
ILFree(idl);
}
ILFree(folder);这导致:
error C2664: 'HRESULT SHOpenFolderAndSelectItems(LPCITEMIDLIST,UINT,LPCITEMIDLIST *,DWORD)': cannot convert argument 3 from '_ITEMIDLIST **' to 'LPCITEMIDLIST *'创建项目数组的好方法是什么?
发布于 2017-11-30 01:38:35
这只是语法错误。你有两个选择:
1.)
使用std::vector<LPCITEMIDLIST> v;
在这种情况下,调用const_cast时需要使用ILFree(const_cast<LPITEMIDLIST>(idl));。
2.)
使用std::vector<LPITEMIDLIST> v;
在这种情况下,需要调用const_cast。
SHOpenFolderAndSelectItems(folder, v.size(), const_cast<LPCITEMIDLIST*>(v.data()), 0);
但是,在这两种情况下,二进制代码都是绝对相同的。
发布于 2017-11-30 01:34:26
如下图所示(工作):
HRESULT hr;
hr = CoInitializeEx(0, COINIT_MULTITHREADED);
ITEMIDLIST *folder = ILCreateFromPath("C:\\testing\\");
std::vector<LPITEMIDLIST> v;
v.push_back(ILCreateFromPath("C:\\testing\\test1.txt"));
v.push_back(ILCreateFromPath("C:\\testing\\test2.txt"));
SHOpenFolderAndSelectItems(folder, v.size(), (LPCITEMIDLIST*)v.data(), 0);
for (auto idl : v)
{
ILFree(idl);
}
ILFree(folder);https://stackoverflow.com/questions/47564192
复制相似问题