在dll中接口方法:long            __fastcall IItemReg(BSTR sGetsureUnitNo, BSTR sHospCode, BSTR sOptNo, int iRows, RcptItems* sRcptItems);
其中,最后一个参数为sRcptItems为一个结构数组
而在c#调用的com接口方法成了 int IItemReg(string sGetsureUnitNo, string sHospCode, string sOptNo, int iRows, ref LhHisSever.RcptItems sRcptItems)
不能传入数组。
望各位大侠帮忙解决

解决方案 »

  1.   

    把这个结构体在C#里再定义一次,记得要描述清楚它的列集信息(marshal)才行。
      

  2.   

    给你个例子:通过Windows消息传递数据。CopyDataStruct,它的结构体定义是:    public struct CopyDataStruct
        {
            public IntPtr dwData;
            public int cbData;
            [MarshalAs(UnmanagedType.LPStr)]
            public string lpData;
        }通过SendMessage传递这个消息的参数时传递这个结构体的指针即可。
      

  3.   

    我如下声明函数,行吗?还有我是调用的com,还需要指向引用[DllImport("Interop.LhHisSever.dll", EntryPoint = "IItemReg", CharSet = CharSet.Ansi)]这行吗?
    [DllImport("Interop.LhHisSever.dll", EntryPoint = "IItemReg", CharSet = CharSet.Ansi)]
            public static extern int IItemReg(string getUnitNo, string hospCode, string operId,int len,[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStruct, SizeConst = 1000)] IntPtr[] ptrs); 
      

  4.   

    com的直接引用就可了,数组的话考虑用safearray
      

  5.   

    不用DllImport还是不得行啊,怎么办??
      

  6.   

    DLLIMPORT 对于com是不可行的,因为com函数不是export函数