首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用CryptCATCatalogInfoFromContext抛出错误

调用CryptCATCatalogInfoFromContext抛出错误
EN

Stack Overflow用户
提问于 2012-09-27 18:48:46
回答 1查看 119关注 0票数 0

我想将函数CryptCATCatalogInfoFromContext称为wintrust.dll中可用的函数。但是当我这样做时,我收到一个错误,它说指定的数组不是预期的类型。,我使用下面的代码来调用方法。我使用的某些数据类型似乎与所需的数据类型不匹配。

代码语言:javascript
复制
    '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了。

代码语言:javascript
复制
        Dim infoStruct As New CATALOG_INFO_()
        infoStruct.cbStruct = 256
        Dim c(255) As Char
        infoStruct.wszCatalogFile = c
        CryptCATCatalogInfoFromContext(CatalogContext, infoStruct, 0)

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-27 19:23:06

是的,申报错误。它不是一个SafeArray,而是一个Unicode字符串。适当的声明是:

代码语言:javascript
复制
<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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12628161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档