0

我想调用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)

最后一行抛出错误指定的数组不是预期的类型。 我是否为数组使用了错误的数据类型?

4

1 回答 1

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
于 2012-09-27T19:23:06.270 回答