将 C# 锯齿状数组编组到 C++
我正在尝试将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用低级 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.