将多维(安全)数组从 C# 传递到 COM

发布于 2024-09-06 10:56:16 字数 146 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦言归人 2024-09-13 10:56:16

我很确定这应该按原样工作。只需确保您传递的是真正的二维数组,而不是锯齿状数组。换句话说,传递 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[][].

身边 2024-09-13 10:56:16

我认为您必须为您的 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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文