问题编组C#交错数组到C ++ [英] Problem Marshalling C# Jagged Array to C++

查看:269
本文介绍了问题编组C#交错数组到C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图封送2D C#交错数组(双击[] [] jaggedArray ),在那里我已经指定的接收变量是一个C ++ DLL 双**

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

不过,我得到的消息:

有是
嵌套数组没有封送处理支持。

There is no marshaling support for nested arrays.

短扁平化的锯齿状排列的是有一个C ++ DLL使用交错数组从C#的方式?

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

推荐答案

使用低水平Marshal类方法,有可能元帅任何类型的非托管内存。例如,对于在jaggedArray每双[]数组,分配非托管内存块与Marshal.AllocHGlobal,并使用Marshal.Copy方法(双[],的Int32,IntPtr的,Int32)方法阵列成员复制到其中。 AllocHGlobal返回的IntPtr类型,这可以被传递到C ++方法poiner,双*在这种情况下

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.

这篇关于问题编组C#交错数组到C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆