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:
Code:
SHFILEINFO *FileInfo = new SHFILEINFO();
// Get a list of files specified by Path
SHGetFileInfo(FileName,
0,
FileInfo,
sizeof(SHFILEINFO),
SHGFI_ICONLOCATION);
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.
So instead I tried another approach that somewhat works but its still broken:
Code:
LPITEMIDLIST Pidl;
LPSHELLFOLDER DesktopFolder;
LPSHELLFOLDER Folder;
OLECHAR OlePath[MAX_PATH];
ULONG Attributes;
HRESULT hr;
IExtractIcon* Extract;
TCHAR Path[MAX_PATH];
LPENUMIDLIST EnumIDL;
unsigned Flags;
int Index;
if (SUCCEEDED(SHGetDesktopFolder(&DesktopFolder)))
{
// 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);
if (SUCCEEDED(hr))
{
// Populate the Icon Extract Interface
hr = DesktopFolder->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST *) &Pidl, IID_IExtractIcon, 0, (void **) &Extract);
if (SUCCEEDED(hr))
{
// 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;
}
}
}
Extract->Release();
}
}
//release the desktop folder object
DesktopFolder->Release();
}
return NULL;
The Index seems to be right but the Path variable ends up pointing to C:\Windows\Explorer.exe. This is obviously false.
Any help on this matter would be greatly appreciated!!