Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 调用CryptCatalogInfofromContext引发错误_Windows_Vb.net_Winapi_Code Signing_Sha1 - Fatal编程技术网

Windows 调用CryptCatalogInfofromContext引发错误

Windows 调用CryptCatalogInfofromContext引发错误,windows,vb.net,winapi,code-signing,sha1,Windows,Vb.net,Winapi,Code Signing,Sha1,我想调用函数cryptCatalogInfofromContext,该函数位于wintrust.dll中。但是当我这样做时,我收到一个错误,说指定的数组不是预期的类型。 我使用以下代码来调用方法。我使用的某些数据类型似乎与所需的数据类型不匹配 'import wintrust.dll <DllImport("Wintrust.dll", PreserveSig:=True, SetLastError:=False)> _ Private Shared Func

我想调用函数cryptCatalogInfofromContext,该函数位于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
最后一行抛出错误指定的数组不是预期的类型。
是否为数组使用了错误的数据类型?

是,声明错误。它不是安全数组,而是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
_
公共结构目录信息
公共广播公司作为UInteger
_
作为字符串的公共wszCatalogFile
端部结构

非常感谢,汉斯。你的调整解决了这个问题。我还将私有共享函数CryptCatalogInfoFromContext(ByVal catalogContext作为IntPtr,ByVal hash作为CATALOG_INFO_,ByVal dwFlags作为Integer)更改为布尔型,以私有共享函数CryptCatalogInfoFromContext(ByVal catalogContext作为IntPtr,ByRef hash作为CATALOG_INFO_,ByVal dwFlags作为Integer)作为布尔值,一切正常工作。再次非常感谢。
<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