2013-08-24 45 views
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位整数值。

任何想法如何驯服这个功能,并使其工作?

+1

http://pinvoke.net/default.aspx/shell32/ExtractIconEx.html –

回答

2
ByRef phiconLarge() As IntPtr, _ 
    ByRef phiconSmall() As IntPtr, _ 

在该网页上的VB.NET声明有一个bug,这些阵列需要传递BYVAL,不为ByRef。请注意他们在页面底部的示例代码中是否正确。

我编辑了页面以纠正错误。