Marshalling C# Jagged Array to C++

后端 未结 1 609
暖寄归人
暖寄归人 2020-12-19 16:19

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**.

相关标签:
1条回答
  • 2020-12-19 17:04

    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 讨论(0)
提交回复
热议问题