gpt4 book ai didi

C++ MFC 从 CLSID (GUID) 创建 IShellItem

转载 作者:行者123 更新时间:2023-11-28 03:37:01 26 4
gpt4 key购买 nike

我必须为 Windows 帮助和 Windows 运行创建一个 ShellItem...

我有这个

Help and Support    {2559a1f1-21d7-11d4-bdaf-00c04f60b9f0}
Run {2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}

来自 http://www.sevenforums.com/tutorials/110919-clsid-key-list-windows-7-a.html

我试过了

IShellFolder* desk = NULL;
HRESULT hr =SHGetDesktopFolder(&desk);
LPITEMIDLIST pidl2=NULL;
ULONG cbEaten;
DWORD dwAttribs = 0 ;

hr = desk->ParseDisplayName(NULL,
NULL,
L"::{2559A1F1-21D7-11D4-BDAF-00C04F60B9F0}",
&cbEaten, // This can be NULL
&pidl2,
&dwAttribs);

它返回 OK 但 Null 作为 pidl2

你们能帮帮我吗?

最佳答案

如果您传递“shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}”,ParseDisplayName 应该能够解析它,但我想这并不是您真正想要的。

ParseDisplayName 能够解析某些::{clsid} 路径,但我认为它仅限于一组非常有限的 CSIDL_* 特殊文件夹。 SHSimpleIDListFromPath 能够解析它。

如果你真的想用 ParseDisplayName 解析它,你可以尝试模拟 SHSimpleIDListFromPath:

class EmptyFileSystemBindData : public IFileSystemBindData {
public:
STDMETHODIMP QueryInterface(REFIID riid, void **ppv)
{
if (riid == IID_IUnknown || riid == IID_IFileSystemBindData) {
*ppv = static_cast<IUnknown*>(this);
AddRef();
return S_OK;
}
*ppv = NULL; return E_NOINTERFACE;
}
STDMETHODIMP_(ULONG) AddRef() { return 2; }
STDMETHODIMP_(ULONG) Release() { return 1; }
STDMETHODIMP SetFindData(const WIN32_FIND_DATAW *pfd)
{
return S_OK;
}
STDMETHODIMP GetFindData(WIN32_FIND_DATAW *pfd)
{
ZeroMemory(pfd,sizeof(WIN32_FIND_DATAW));
return S_OK;
}
};

LPITEMIDLIST pidl2=NULL;
HRESULT hr;
IShellFolder*psf;
IBindCtx*pbc;
hr = CreateBindCtx(0,&pbc);
EmptyFileSystemBindData efsbd;
if (SUCCEEDED(hr))
{
BIND_OPTS bo = {sizeof(bo)};
bo.grfMode = STGM_CREATE;
hr = pbc->RegisterObjectParam(STR_FILE_SYS_BIND_DATA,&efsbd);
if (SUCCEEDED(hr) && 0==pbc->SetBindOptions(&bo))
{
hr = SHGetDesktopFolder(&psf);
if (SUCCEEDED(hr))
{
hr = psf->ParseDisplayName(0,pbc,L"::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}",0,&pidl2,0);
if (SUCCEEDED(hr))
{
OutputDebugStringA("parsed ok\n");
ILFree(pidl2);
}
psf->Release();
}
}
pbc->Release();
}

关于C++ MFC 从 CLSID (GUID) 创建 IShellItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10587526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com