Thats not a problem for me because I will build a map of my own descriptors to those indexes. For some reason when I use SHGetFileInfo, what I get back is an index but no location. For example, what if an exe or shortcut has its own ICO file embedded inside the EXE. I would want to get at that icon so that I could draw it in my program.
here is the first way I tried to get at the Index and Path:
According the MSDN docs, this way should have returned an index in FileInfo->iIcon (Which it does, correctly) and also the path to the file that contains this resource inside FileIno->szDisplayName. The display name always ends up being a NULL string.
SHFILEINFO *FileInfo = new SHFILEINFO();
// Get a list of files specified by Path
So instead I tried another approach that somewhat works but its still broken:
The Index seems to be right but the Path variable ends up pointing to C:\Windows\Explorer.exe. This is obviously false.
// Convert to Unicode
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, FileName, -1, OlePath, MAX_PATH);
// Convert the path to an ITEMIDLIST.
hr = DesktopFolder->ParseDisplayName(NULL, NULL, OlePath, NULL, (LPITEMIDLIST *) &Pidl, &Attributes);
// Populate the Icon Extract Interface
hr = DesktopFolder->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST *) &Pidl, IID_IExtractIcon, 0, (void **) &Extract);
// retrieve the Icon Path and Index
if (SUCCEEDED(Extract->GetIconLocation(GIL_OPENICON, Path, _MAX_PATH, &Index, &Flags)))
if (!(Flags & GIL_NOTFILENAME))
if (Index == -1)
// Special case for Control Panel Apps
Index = 0;
//release the desktop folder object
Any help on this matter would be greatly appreciated!!