Icon extraction on .exe and dll. files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello everybody!

I am currently developing a sidebar-application and getting stucked in the
problem of extracting the default application icon of .exe and .dll files.
Has anybody out there a solution in VB . Net?

I tried a solution using LoadLibraryEx, LoadResource, FindResource,
ExtractIcon etc. but only run into StackOverflow errors. Hence I guess that
the HICON-structure of the native window system and the .NET Icon-class
differ in some (or more probable: many) ways. For example ExtractIcon(...)
returns a handle on an icon. Trying to use this handle by
Icon.FromHandle(handle) results in a StackOverflow error.

Regards,
Joachim
 
I've found a solution that works fine:

Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" _
(ByVal lpszFile As String, _
ByVal nIconIndex As Integer, _
ByRef phiconLarge As Integer, _
ByRef phiconSmall As Integer, _
ByVal nIcons As Long) As Integer

....

handle = ExtractIcon(Me.Handle.ToInt32, .FileName, 0)
If handle > 0 Then

Dim icn As Icon = Icon.FromHandle(New IntPtr(handle))
Dim bmp as Bitmap = icn.ToBitmap()

...

End If

Thx for your interest!
Joachim
 
Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal
hInst As Integer, ByVal lpszExeFileName As String, ByVal nIconIndex As
Integer) As Integer
 
Joachim said:
I am currently developing a sidebar-application and getting stucked in the
problem of extracting the default application icon of .exe and .dll files.
Has anybody out there a solution in VB . Net?

In addition to the other replies: DLLs don't have a default application
icon, at least not in Explorer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top