调用com接口传递struct数组问题

Dkywolf 2008-09-09 09:50:51
在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)
不能传入数组。
望各位大侠帮忙解决
...全文
182 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dkywolf 2008-09-11
  • 打赏
  • 举报
回复
没人来,自己顶一下
Dkywolf 2008-09-11
  • 打赏
  • 举报
回复
都卡了几天了,望各位大哥帮帮忙啊。
在下先谢过了
Dkywolf 2008-09-11
  • 打赏
  • 举报
回复
望举个例子作解答?
whycom 2008-09-10
  • 打赏
  • 举报
回复
com的直接引用就可了,数组的话考虑用safearray
Dkywolf 2008-09-10
  • 打赏
  • 举报
回复
我如下声明函数,行吗?还有我是调用的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);
whycom 2008-09-10
  • 打赏
  • 举报
回复
DLLIMPORT 对于com是不可行的,因为com函数不是export函数
Dkywolf 2008-09-10
  • 打赏
  • 举报
回复
不用DllImport还是不得行啊,怎么办??
brallow 2008-09-09
  • 打赏
  • 举报
回复
给你个例子:通过Windows消息传递数据。CopyDataStruct,它的结构体定义是:

public struct CopyDataStruct
{
public IntPtr dwData;
public int cbData;
[MarshalAs(UnmanagedType.LPStr)]
public string lpData;
}

通过SendMessage传递这个消息的参数时传递这个结构体的指针即可。
brallow 2008-09-09
  • 打赏
  • 举报
回复
把这个结构体在C#里再定义一次,记得要描述清楚它的列集信息(marshal)才行。

110,572

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧