问题从C#传递阵列C ++ [英] Problem in passing arrays from C# to C++
问题描述
我有,我需要从C#的数组传递给C ++ DLL的应用程序。什么是做到这一点的最好方法是什么?我做了一些互联网搜索和想通了,我需要通过参考使用C#中的数组。对于相同的代码:
状态= IterateCL(REF输入,输出参考);
的输入和输出数组是长度20的并在C ++中的DLL对应的代码是对>
IterateCL为(int *&放大器; inArray,为int *&安培; outArray)
这一次正常工作。但是,如果我尝试调用从C#中的函数在一个循环中的第二次,在C#中输入数组被显示为一个元素的数组。为什么会出现这种情况,请您帮我,我怎么能叫从C#迭代此功能。
谢谢,
拉克什。
< DIV CLASS =h2_lin>解决方案
您需要使用:
函数[DllImport(your_dll )]
公众的extern无效IterateCL([IN,的MarshalAs(UnmanagedType.LPArray)INT [] ARR1,[出,的MarshalAs(UnmanagedType.LPArray)INT [] ARR2);
I have an application in which I need to pass an array from C# to a C++ DLL. What is the best method to do it? I did some search on Internet and figured out that I need to pass the arrays from C# using ref. The code for the same:
status = IterateCL(ref input, ref output);
The input and output arrays are of length 20. and the corresponding code in C++ DLL is
IterateCL(int *&inArray, int *&outArray)
This works fine for once. But if I try to call the function from C# in a loop the second time, the input array in C# is showing up as an array of one element. Why is this happening and please help me how I can call this function iteratively from C#.
Thanks, Rakesh.
You need to use:
[DllImport("your_dll")]
public extern void IterateCL([In, MarshalAs(UnmanagedType.LPArray)] int[] arr1, [Out, MarshalAs(UnmanagedType.LPArray)] int[] arr2);
这篇关于问题从C#传递阵列C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!