IShellFolder :: ParseDisplayName获取控制面板项的ITEMIDLIST

时间:2016-11-14 14:42:59

标签: c++ windows-shell shell-extensions

我有Shell文件夹,它是一个控制面板项目。我试图获得相同的ITEMIDLIST。我有Shell文件夹GUID。

通过文档

https://msdn.microsoft.com/en-us/library/windows/desktop/bb775090%28v=vs.85%29.aspx

https://msdn.microsoft.com/en-us/LIBRary/ms909875.aspx,不一致

并声明我可以从Desktop Folder中以:: {GUID}语法指定显示名称,我试过

::{CLSID for Control Panel}\::{CLSID for my Shell folder}.

然而,当我最终使用控制面板的ITEMIDLIST时,这并不起作用。如何将ITEMIDLIST转到控制面板项目?

根据@Denis Anisimov的回答,我仍然面临ParseDisplayName的问题。

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HRESULT hres;
LPSHELLFOLDER cPanel;
LPSHELLFOLDER DesktopFolder;
LPITEMIDLIST cpItemPidl;
LPITEMIDLIST pidl;
SHGetDesktopFolder(&DesktopFolder);
SHGetKnownFolderIDList(FOLDERID_ControlPanelFolder, CSIDL_CONTROLS, NULL, &pidl);
hres = DesktopFolder->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&cPanel);
LPWSTR SFOLDERGUID = L"::{025A5937-A6BE-4686-A844-36FE4BEC8B6D}";

hres = cPanel->ParseDisplayName(NULL, NULL, SFOLDERGUID, NULL, &cpItemPidl, NULL);
}

我得到的是野兔

E_INVALIDARG One or more arguments are invalid.

1 个答案:

答案 0 :(得分:1)

我的工作项目的一部分(它是Delphi,但主要原则是可见的):

function CreatePluginsPIDL: PItemIDList;
var
  ControlPanelPIDL: PItemIDList;
  PluginsParsingName: UnicodeString;
  Desktop: IShellFolder;
  ControlPanelFolder: IShellFolder;
  Eaten: DWORD;
  Attr: DWORD;
  Child: PItemIDList;
begin
  ControlPanelPIDL := GetKnownFolderIDList(FOLDERID_ControlPanelFolder, CSIDL_CONTROLS);
  try
    OleCheck(SHGetDesktopFolder(Desktop));
    try
      OleCheck(Desktop.BindToObject(ControlPanelPIDL, nil, IShellFolder, ControlPanelFolder));
      try
        PluginsParsingName := '::' + GUIDToString(TTC4ShellCPNamespaceCLSID);
        Attr := 0;
        OleCheck(ControlPanelFolder.ParseDisplayName(0, nil, PWideChar(PluginsParsingName), Eaten, Child, Attr));
        try
          Result := ILCombine_(ControlPanelPIDL, Child);
        finally
          CoTaskMemFree(Child);
        end;
      finally
        ControlPanelFolder := nil;
      end;
    finally
      Desktop := nil;
    end;
  finally
    CoTaskMemFree(ControlPanelPIDL);
  end;
end;