Peaked
Peaked

Reputation: 118

IShellFolder::ParseDisplayName to get ITEMIDLIST for Control Panel Item

I have Shell Folder which is a Control Panel Item. I'm trying to get the ITEMIDLIST for the same. I have the Shell Folder GUID.

Going by the documentation

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

https://msdn.microsoft.com/en-us/LIBRary/ms909875.aspx, which are not consistent

and state that I can specify display name in ::{GUID} syntax from Desktop Folder, I tried

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

This however doesn't work as I end up with the Control Panel's ITEMIDLIST. How do I get ITEMIDLIST to the Control Panel Item?

With the answer suggested by @Denis Anisimov, I still face issues with 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);
}

I get hres as

E_INVALIDARG One or more arguments are invalid.

Upvotes: 0

Views: 1397

Answers (1)

Denis Anisimov
Denis Anisimov

Reputation: 3317

Part of my working project (it is Delphi but the main principle is visible):

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;

Upvotes: 1

Related Questions