因为我需要从文件中提取一个图标,而不是第一个图标,所以我无法使用 vb.net 图标提取功能。应该执行此操作的 WIN32API 函数需要一个指向整数数组的指针。
如何提供这种类型作为参数?
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)
我已经看了一下System.Reflection.Pointer
class?/namespace?,但是文档很少而且不太明智。
IntPtr
不提供对数组 afaikt 的支持
Ok tx to Hans 我已经设法将签名更正为:
<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
...
随后的调用总是会导致异常 ( Value cannot be null
)。我得到一个返回值4294967295
,它是最大的 32 位整数值。
任何想法如何驯服此功能并使其工作?