将多维(安全)数组从 C# 传递到 COM
我有一个 COM 对象,它采用 0 有界的二维安全数组。我需要将此数组传递到我的 C++ COM 对象中。我可以毫无问题地将 VB6 multidim 数组传递到 C++ 端,但我不知道如何在 C# 中进行设置,以便正确编组。有谁知道设置多维数组并将其传递给 COM 的步骤吗?
I have a COM object that takes a 0 bounded safearray of two dimensions. I need to pass this array into my C++ COM object. I can pass the VB6 multidim arrays into the C++ side without a problem, but I have no idea how to set this up in C# so that it will be marshalled correctly. Does anyone know the steps to set up a mulitidimensional array and pass it to COM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很确定这应该按原样工作。只需确保您传递的是真正的二维数组,而不是锯齿状数组。换句话说,传递 arr[,] 而不是 arr[][]。
I'm pretty sure that should work as-is. Just make sure that you pass a true 2-dimensional array, not a jagged array. In other words, pass arr[,] not arr[][].
我认为您必须为您的 C++ COM dll 生成标准 com 互操作(例如,将其添加为对您的 c# 项目的引用)。然后我认为 C# 应该正确地将标准 .Net(多维)数组编组为 com 安全数组。试一试吧:)
I think you have to generate a standard com interop for your C++ COM dll (e.g. add it as a reference to your c# project). Then I think C# should correctly marshal a standard .Net (multidimentional) array as a com safe array. Just give it a go :)