2

Does Windows API offer any way to obtain a special folder path (i.e. My Documents), given its CLSID as string (i.e. ::{450d8fba-ad25-11d0-98a8-0800361b1103})? Can this be done in any way? Also, it should be done with functions supported under Windows XP.

Thank you in advance.

Sekoraiko
  • 35
  • 4
  • What is that GUID? CLSIDs identify COM classes. Is that a known folder ID? Please elaborate. – David Heffernan Oct 08 '14 at 18:33
  • I know, it is confusing to me too since CLSIDs identify COM classes as you said. It's a string that identifies a Windows special folder, there's a list of them here: http://www.thewindowsclub.com/the-secret-behind-the-windows-7-godmode. If you paste that string in the run dialog (Ctrl+R) it will open "My Documents" folder. Windows is resolving it to a path in some way and i'd like to know how it can be done – Sekoraiko Oct 08 '14 at 18:38
  • What are you really trying to do? – David Heffernan Oct 08 '14 at 18:44
  • I'm developing a program that receives the path to a directory as parameter. Such path can be given as a full qualified path (i.e. "C:\Users\admin\Documents\Projects"), or using one of those guids (i.e. "::{450d8fba-ad25-11d0-98a8-0800361b1103}\Projects"). If the path is provided in the second form, I need to be capable of translating it to its full path. – Sekoraiko Oct 08 '14 at 18:50

1 Answers1

4

The fundamental API you need for this is SHParseDisplayName. That will take the ::{GUID} format path and convert it to a PIDL.

If the PIDL then has a string form (as your example does, since it resolves to the Documents folder), you can use SHGetPathFromIDList to convert it.

LPITEMIDLIST pidl;
if (SUCCEEDED(SHParseDisplayName(L"::{450d8fba-ad25-11d0-98a8-0800361b1103}", nullptr, &pidl, 0, nullptr)))
{
    wchar_t wchPath[MAX_PATH];
    if (SUCCEEDED(SHGetPathFromIDList(pidl, wchPath)))
    {
        // string form of path is now in wchPath
    }
    ILFree(pidl);
}
Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79