Steal icons from another EXE|DLL in .NET :)

July 13, 2006

Heres a way to get icons from another exe or dll file. You can use Win32 apis to do this task.

Private 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 Integer) As Integer

Private Declare Function ExtractIcon Lib “shell32.dll” Alias “ExtractIconA” (ByVal hInst As IntPtr, ByVal lpszExeFileName As String, ByVal nIconIndex As Integer) As Integer

Private Declare Function DrawIconEx Lib “user32” (ByVal hdc As Integer, ByVal xLeft As Integer, ByVal yTop As Integer, ByVal hIcon As IntPtr, ByVal cxWidth As Integer, ByVal cyWidth As Integer, ByVal istepIfAniCur As Integer, ByVal hbrFlickerFreeDraw As Integer, ByVal diFlags As Integer) As Integer

Private Declare Function DestroyIcon Lib “user32.dll” (ByVal hIcon As Integer) As Integer

These are the apis which would be needed.

Explanation and usage:

1. First use the ExtractIconEx to get the number of icons in the specified file.

Dim numOfIcons as Integer = ExtractIconEx(“filepath”, -1, 0&, 0&, 0&)

2. Using FOR loop get handles [i.e iconHandle] to all the icons using the ExtractIcon

3. Create the icon object from the handles

Dim myicon as System.Drawing.Icon = System.Drawing.Icon.FromHandle(iconHandle)

And you are all done. Now that you have the icon, you can use it in your application or write a bitmap out of it.

-Bugs!

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: