Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Into a VB.NET project that I am working on, there is a function by the name "ReturnIcon" which extracts icons from .exe, .dll, .ico etc and return them to bitmap.

I would like to add the ability so I can get count of stored icons for selected file. There is anyway to add it into this function? Should I make a new one for this? Any example would be really appreciatable!

What I have tried:

VB
Declare Function ExtractIcon 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

Public Function ReturnIcon(ByVal Path As String, ByVal Index As Integer, Optional ByVal small As Boolean = False) As Icon
    Dim bigIcon As Integer
    Dim smallIcon As Integer

    ExtractIcon(Path, Index, bigIcon, smallIcon, 1)
    If bigIcon = 0 Then
        ExtractIcon(Path, 0, bigIcon, smallIcon, 1)
    End If

    If bigIcon <> 0 Then
        If small = False Then
            Return Icon.FromHandle(bigIcon)
        Else
            Return Icon.FromHandle(smallIcon)
        End If
    Else
        Return Nothing
    End If
End Function
And you can use it like this:
VB
X_Control.Image = ReturnIcon(IconPath, 0, 0).ToBitmap
Posted
Updated 3-Feb-18 5:09am

1 solution

I would create a new function (Single purpose and all that).

You might be able to adapt the concepts on this CP article Extract icons from EXE or DLL files[^] (sorry it's C#) or this MSDN one Extracting Icons Using win32 API ExtractIconEx[^]
 
Share this answer
 
Comments
Simos Sigma 3-Feb-18 13:26pm    
Thank you very much my friend, I found what I wanted in your second link. I just had to do this...
Dim count As Integer = ExtractIcon(FilePath, -1, Nothing, Nothing, 0)
Maciej Los 4-Feb-18 6:35am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900