开发者

Marshalling C# Jagged Array to C++

开发者 https://www.devze.com 2023-03-12 17:05 出处:网络
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**.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消