Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
Com interop 使用复杂结构从.NET调用Win32 DLL_Com Interop - Fatal编程技术网

Com interop 使用复杂结构从.NET调用Win32 DLL

Com interop 使用复杂结构从.NET调用Win32 DLL,com-interop,Com Interop,我已将一个旧的VB6组件升级到.NET。此组件调用了另一个Win32组件,其类型结构如下: Public Type DDPARAMS bAddressFlag As String * 1 bCompanyFlag As String * 1 bNameFlag As String * 1 bPremiseFlag As String * 1

我已将一个旧的VB6组件升级到.NET。此组件调用了另一个Win32组件,其类型结构如下:

Public Type DDPARAMS
    bAddressFlag As String * 1                  
    bCompanyFlag As String * 1                  
    bNameFlag As String * 1                    
    bPremiseFlag As String * 1      
..etc
我无法引用此Win32 DLL,因为它不是COM DLL,因此.NET无法自动为我创建任何互操作

我有用C编写的Win32 DLL的原始源代码,结构定义如下:

typedef struct tagDDPARAMS
    {

    BYTE bAddressFlag;             
    BYTE bCompanyFlag;              
    BYTE bNameFlag;                 
    BYTE bPremiseFlag;              

    BYTE sPremiseThreshold[3];    

etc.
升级VB6组件时,为结构生成的.NET代码为:

公共结构参数 作为字符的公共标志

    <VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=1)> Public bCompanyFlag() As Char 

    <VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=1)> Public bNameFlag() As Char 

    <VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=1)> Public bPremiseFlag() As Char 

    <VBFixedString(3), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=3)> Public sPremiseThreshold() As Char 

    <VBFixedString(3), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=3)> Public sLooseThreshold() As Char 
等等

但是,当我运行此代码时,会出现以下错误:

无法封送类型,因为嵌入数组实例的长度与布局中声明的长度不匹配

我在谷歌上搜索了又搜索,我已经失去了主意——任何帮助都是感激的

更新:我尝试了下面的建议,并将ByValArray更改为AnsiBStr单字节字符串,现在得到以下结果:

无法封送“DDRECORD”类型的字段“sTown”:无效的托管/非托管类型组合数组字段必须与ByValArray或SafeArray成对出现

非常感谢
邓肯:看来你的声明弄错了。检查,也许这有助于你找到合适的类型。我假设bAddressFlag在VB中应该是Byte而不是char,并且应该使用UnmanagedType.U1声明

不过这只是一个猜测