本文介绍了C ++ MFC从CLSID(GUID)创建IShellItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to create a ShellItem to Windows Help and Windows Run...

我有这个

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

来自

我试过了

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

It returns OK but Null as pidl2

$ p

could you guys give me some help?

推荐答案

ParseDisplayName应该能够解析它,如果你传递shell ::: {

ParseDisplayName should be able to parse it if you pass "shell:::{2559a1f3-21d7-11d4-bdaf-00c04f60b9f0}" but I guess that is not really what you want.

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

ParseDisplayName is able to parse some ::{clsid} paths but I think it is restricted to a very limited set of CSIDL_* special folders. SHSimpleIDListFromPath was able to parse it.

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

If you really want to parse it with ParseDisplayName you can try to emulate 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 16:30