I am trying to wrap a C++ library for using in a C# WPF project. As part of that I need to pass and return large arrays from C# to C++ and return a large array back. Passing the array seems to be achieved like this:
namespace CppWrapper {
public ref class CppWrapperClass
{
public:
void DoStuff(int* pInt, int arraySize);
private:
computingClass* pCC;
};
}
And then called like this:
int noElements = 1000;
int[] myArray = new int[noElements];
for (int i = 0; i < noElements; i++)
myArray[i] = i * 10;
unsafe
{
fixed (int* pmyArray = &myArray[0])
{
CppWrapper.CppWrapperClass controlCpp = new CppWrapper.CppWrapperClass();
controlCpp.DoStuff(pmyArray, noElements);
}
}
How do I return an array?
Note: I would appreciate any feedback on the best way of achieving this. I am surprised it is not easier to this from C# to C++. I found it much easier wrapping the library with JNI.