Because I need to extract an icon from a file, but not the first icon, I cannot use the vb.net icon extraction function. The WIN32API function that should do this expects a pointer to an integer array.
How can I provide this type as a parameter?
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
Dim icons As integer()
ExtractIconEx("%systemroot%/shell32.dll", 15, icons, 0, 5)
I've taken a gander at the System.Reflection.Pointer class?/namespace?, but the documentation is sparse and less than sensible.
IntPtr doesn't provide support for arrays afaikt
Ok tx to Hans I've managed to correct the signature to:
<Runtime.InteropServices.DllImport("shell32.dll", _
CharSet:=Runtime.InteropServicesCharSet.Auto)> _
Shared Function ExtractIconEx(ByVal szFileName As String, _
ByVal nIconIndex As Integer, _
ByRef phiconLarge() As IntPtr, _
ByRef phiconSmall() As IntPtr, _
ByVal nIcons As UInteger) As UInteger
End Function
...
Dim icons(8) As IntPtr, smicons(8) As IntPtr
MsgBox(ExtractIconEx("%systemroot%/shell32.dll", 15, icons, smicons, 1))
Try
MsgBox(icons.Count)
Catch ex As Exception
MsgBox(ex.Message & " by " & ex.Source)
End Try
...
The subsequent calls always cause an exception (Value cannot be null). I get a return value of 4294967295, which is the maximum 32 bit integer value.
Any ideas how to tame this function and make it work?