I'm on Windows 10 Pro and Visual Studio 2013, and I'm using SHGetFileInfoW
to get an icon location (path + index) for a file type:
std::wstring wFile { L"a.bas" };
SHFILEINFOW fi {};
DWORD success = ::SHGetFileInfoW(wFile.c_str(),
FILE_ATTRIBUTE_NORMAL,
&fi,
sizeof(fi),
SHGFI_USEFILEATTRIBUTES | SHGFI_ICONLOCATION);
No matter whether wFile
refers to an existing file or is just any filename, the call returns 1 indicating success. The iIcon
member of fi
is set to a number, but szDisplayString
is empty. Not just the drive letter is overwritten with
(as seemed to happen here) but it is completely filled with
.
Microsoft recommends using IExtractIcon
::
GetIconLocation
as an alternative, but I need to get the icon for files which are not on a local filesystem, so I can't get an IShellInfo
object which would get me this interface pointer.
Getting an icon handle works, on the other hand. Is this function just buggy or am I doing something wrong? Is there a workaround?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…