0
因爲我需要從文件中提取圖標,但不是第一個圖標,所以我無法使用vb.net圖標提取功能。應該這樣做的WIN32API函數需要一個指向整型數組的指針。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
類?/?的命名空間,但文件是稀疏的和小於明智的。
IntPtr
不會對數組漢斯提供支持afaikt
正常Tx我已經設法糾正簽名:
<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位整數值。
任何想法如何馴服這個功能,並使其工作?
http://pinvoke.net/default.aspx/shell32/ExtractIconEx.html –