问题描述
在平凡的情况下,我可以成功使用 SHOpenFolderandSelectItems()
。代码类似于以下内容:
I can successfully use SHOpenFolderandSelectItems()
in trivial cases. Code looks similar to this:
ITEMIDLIST *idl = ILCreateFromPath(L"C:\\testing\\example.txt");
SHOpenFolderAndSelectItems(idl, 0, 0, 0);
ILFree(idl);
现在我想做的是打开一个文件夹并选择其中的多个文件。但是我对 SHOpenFolderAndSelectItems()
的期望感到困惑。简化了,这就是我要尝试的:
Now what I'd like to do is open up a folder and select multiple files within it. But I'm confused as to what SHOpenFolderAndSelectItems()
is expecting. Simplified, this is what I'm trying:
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 *'
创建项目数组的一种体面方法是什么?
What is a decent way to create the array of items?
推荐答案
这只是语法错误。您有2种选择:
this is only syntax error. you have 2 choice:
1。)
使用 std :: vector< LPCITEMIDLIST> v;
在这种情况下,您需要在调用 ILFree(const_cast< LPITEMIDLIST>(idl));时使用 const_cast ;
in this case you need use const_cast when call ILFree(const_cast<LPITEMIDLIST>(idl));
2。)
使用 std :: vector< ; LPITEMIDLIST> v;
在这种情况下,您需要 const_cast 通话
in this case you need const_cast in call
SHOpenFolderAndSelectItems(文件夹,v.size(),const_cast< LPCITEMIDLIST *>(v.data()),0);
但是两种情况下的二进制代码绝对相同
however binary code will be absolute the same in both case
这篇关于SHOpenFolderAndSelectItems()与数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!