2

How can I get the PIDL of a library from its GUID?

For example, if I have the GUID of the Documents library ("{7B0DB17D-9CD2-4A93-9733-46CC89022E7C}"), how can I convert that into the library's ID list?

I thought SHParseDisplayName would do the job, but it returns "file not found."

Bear in mind that what I need is the PIDL of the library, not of its default folder.

This is straight C++, no .Net.

TIA

Edit: This is the code that works, from the response below (without error checks). guid is a GUID string prepended with 'shell:::', e.g., 'shell:::{7B0DB17D-9CD2-4A93-9733-46CC89022E7C}'.

IShellFolder* pDesktop;
LPITEMIDLIST pidl;
SHGetDesktopFolder(&pDesktop);
pDesktop->ParseDisplayName(nullptr, nullptr, guid, nullptr, &pidl, 0);

Edit 2: Even easier: SHParseDisplayName works if the 'shell:::' is prepended:

SHParseDisplayName(guid, nullptr, &pidl, 0, nullptr); 
chrisd
  • 853
  • 1
  • 9
  • 23

2 Answers2

2

According to the documentation for IShellFolder::ParseDisplayName you can simply pass it a filename in the form ::{GUID} if you are using the desktop folder.

Edit: the documentation appears to be incomplete, according to this answer you need to add shell: to the start of the string.

p->ParseDisplayName(m_hWnd, NULL, _T("shell:::{7B0DB17D-9CD2-4A93-9733-46CC89022E7C}"), NULL, &pidl, NULL);
Community
  • 1
  • 1
Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • Brilliant! It works when you add 'shell:::'. I understand that the syntax depends on the implementation of the particular interface, but still, MS could have been more helpful on this. Thanks. – chrisd Jul 17 '15 at 18:51
1

You want the function SHGetKnownFolderIDList.

For example:

PIDLIST_ABSOLUTE pidl;
HRESULT hr = SHGetKnownFolderItem(FOLDERID_DocumentsLibrary, 0, NULL, out pidl);

Bonus Chatter

There are three shell functions for dealing with KNOWNFOLDERs

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219