Marshalling C# Jagged Array to C++

随声附和 提交于 2019-11-30 09:03:35

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6327196/marshalling-c-sharp-jagged-array-to-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!