Hello everyone,
Im trying to obtain the file associated icon, I know that i can do this with the api function SHgetFileInfo but I cant get it to work in C++ .net what i have so far is
[StructLayoutAttribute(LayoutKind::Sequential)]
__gc struct SHFILEINFO
{
public:
const static int NAMESIZE = 80;
IntPtr hIcon;
int iIcon;
unsigned int dwAttributes;
String* szDisplayName;
String* szTypeName;
};
[DllImportAttribute("Shell32.dll",CharSet=CharSet::Auto)]
extern "C" unsigned int* SHGetFileInfo(String* pszPath,unsigned int dwFileAttributes,SHFILEINFO* psfi,unsigned int cbFileInfo,unsigned int uFlags);
int _tmain(void)
{
SHFILEINFO* sfi;
SHGetFileInfo("c:\\test.txt",FILE_ATTRIBUTE_NORMAL,sfi,Marshal::SizeOf(__typeof(SHFILEINFO)),SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
return 0;
}
It runs whitout erros but the SHFILEINFO struct sfi remains empty and I havent got a clue why , I am fairly new to C++ and .Net so every help is realy appreciated.
Thanx in advance,
Im trying to obtain the file associated icon, I know that i can do this with the api function SHgetFileInfo but I cant get it to work in C++ .net what i have so far is
[StructLayoutAttribute(LayoutKind::Sequential)]
__gc struct SHFILEINFO
{
public:
const static int NAMESIZE = 80;
IntPtr hIcon;
int iIcon;
unsigned int dwAttributes;
String* szDisplayName;
String* szTypeName;
};
[DllImportAttribute("Shell32.dll",CharSet=CharSet::Auto)]
extern "C" unsigned int* SHGetFileInfo(String* pszPath,unsigned int dwFileAttributes,SHFILEINFO* psfi,unsigned int cbFileInfo,unsigned int uFlags);
int _tmain(void)
{
SHFILEINFO* sfi;
SHGetFileInfo("c:\\test.txt",FILE_ATTRIBUTE_NORMAL,sfi,Marshal::SizeOf(__typeof(SHFILEINFO)),SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
return 0;
}
It runs whitout erros but the SHFILEINFO struct sfi remains empty and I havent got a clue why , I am fairly new to C++ and .Net so every help is realy appreciated.
Thanx in advance,