我有一个Shell文件夹,它是一个控制面板项目。我正在尝试获取相同的ITEMIDLIST。我有外壳文件夹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,不一致

并指出我可以从桌面文件夹以:: {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.

最佳答案

我的工作项目的一部分(它是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;

07-27 16:32