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:
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:
X_Control.Image = ReturnIcon(IconPath, 0, 0).ToBitmap