我想调用 wintrust.dll 中提供的函数 CryptCATCatalogInfoFromContext 。但是当我这样做时,我收到一个错误,指出指定的数组不是预期的类型。 我使用以下代码来调用方法。似乎我使用的某些数据类型与所需的数据类型不匹配。
'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)
最后一行抛出错误指定的数组不是预期的类型。 我是否为数组使用了错误的数据类型?
答案 0 :(得分:1)
是的,错误的声明。它不是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 Structure