将 C# 锯齿状数组编组到 C++

发布于 2024-11-15 06:38:13 字数 237 浏览 10 评论 0原文

我正在尝试将 2D C# 锯齿状数组 (double[][] jaggedArray) 编组到 C++ dll,其中我已将接收变量指定为 double** >。

但是,我收到消息:

没有编组支持 嵌套数组。

除了展平锯齿状数组之外,是否有办法在 C++ dll 中使用 C# 中的锯齿状数组?

I'm trying to marshal a 2D C# jagged array (double[][] jaggedArray) to a C++ dll where i've specified the receiving variable to be a double**.

However, i'm getting the message:

There is no marshaling support for
nested arrays.

Short of flattening the jagged array is there a way to use jagged arrays from C# in a C++ dll?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

早乙女 2024-11-22 06:38:13

使用低级 Marshal 类方法,可以将任何类型封送到非托管内存。例如,对于 jaggedArray 中的每个 double[] 数组,使用 Marshal.AllocHGlobal 分配非托管内存块,并使用 Marshal.Copy Method (Double[], Int32, IntPtr, Int32) 方法将数组成员复制到其中。 AllocHGlobal 返回 IntPtr 类型,可以将其作为指针传递给 C++ 方法,在本例中为 double*。

Using low level Marshal class methods, it is possible to marshal any type to unmanaged memory. For example, for every double[] array in jaggedArray, allocate unmanaged memory block with Marshal.AllocHGlobal, and copy array members to it using Marshal.Copy Method (Double[], Int32, IntPtr, Int32) method. AllocHGlobal returns IntPtr type, which can be passed to C++ method as poiner, double* in this case.

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