我想将函数CryptCATCatalogInfoFromContext称为wintrust.dll中可用的函数。但是当我这样做时,我收到一个错误,它说指定的数组不是预期的类型。,我使用下面的代码来调用方法。我使用的某些数据类型似乎与所需的数据类型不匹配。
'import wintrust.dll
<DllImport("Wintrust.dll", PreserveSig:=True, SetLastError:=False)> _
Private Shared Function CryptCATCatalogInfoFromContext(ByVal catalogContext As IntPtr, ByVal hash As CATALOG_INFO_, ByVal dwFlags As Integer) As Boolean
End Function
'create structure CATALOG_INFO
<StructLayout(LayoutKind.Sequential)> _
Public Structure CATALOG_INFO_
Public cbStruct As UInteger
<MarshalAs(UnmanagedType.SafeArray)> _
Public wszCatalogFile() As Char
End Structure我已经拿到CatalogContext了。
Dim infoStruct As New CATALOG_INFO_()
infoStruct.cbStruct = 256
Dim c(255) As Char
infoStruct.wszCatalogFile = c
CryptCATCatalogInfoFromContext(CatalogContext, infoStruct, 0)最后一行抛出错误指定的数组不是预期的类型。是否对数组使用了错误的数据类型?
发布于 2012-09-27 19:23:06
是的,申报错误。它不是一个SafeArray,而是一个Unicode字符串。适当的声明是:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure CATALOG_INFO
Public cbStruct As UInteger
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public wszCatalogFile As String
End Structurehttps://stackoverflow.com/questions/12628161
复制相似问题