How extract associated icon

  • Thread starter Thread starter Alexander VS
  • Start date Start date
A

Alexander VS

Hello all!
How can i exract an icon associated with a file?
I found API function ExtractAssociatedIcon, but can i use
this function with VB.Net?
Can i do it easier with some .Net class?

Thanks.
 
Hi,
You can use the ExtractAssociatedIcon API in VB.net to get a handle to an
icon. Here is how you should declare it in VB.net.

Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias
"ExtractAssociatedIconA" (ByVal hInst As IntPtr, ByVal lpIconPath As
String, ByRef lpiIcon As Integer) As IntPtr

You need to use the IntPtr data type whenver a handle is expected in a API.
Also instead of long, use the Integer data type.

You can call the API as follows
Dim y as IntPtr

y = ExtractAssociatedIcon(Process.GetCurrentProcess().Handle, "c:\program
files\microsoft office\office10\excel.exe", 1)


Once you get the handle, you can use it in other API's and also you can
check you the System.Drawing.Icon class.

Hope this helps.


Anand Balasubramanian
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks
 
Anand,
y = ExtractAssociatedIcon(Process.GetCurrentProcess().Handle, "c:\program
files\microsoft office\office10\excel.exe", 1)

Process.GetCurrentProcess().Handle returns a process handle, not a
HINSTANCE which is what ExtractAssociatedIcon expects. You probably
want to use Marshal.GetHINSTANCE instead.



Mattias
 
Back
Top