Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello everyone,

 

I'm trying to obtain the file associated icon, I know that i can do this with the api function SHgetFileInfo but I can't 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 haven't got a clue why , I am fairly new to C++ and .Net so every help is realy appreciated.

 

Thanx in advance,

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...