C# passing double array to C++ dll

2019-09-03 10:21发布

问题:

I have an array initialized in C# code; Then I am going to pass it to C++ dll in which each single entry of the array will be re-assigned with new value. Then the array with be returned back to C# with the new value. I am wondering

  1. what is the best way to pass the array from C# to C++? (Data structure of this array in C#)
  2. What is the best way to return the array from C++? (Data structure of this array in C++)

My code is not working:

In C#

private static double[] _statsArray = new double[4];
GetImageStats( ref _statsArray);

In C++ dll:

DllExportImageStatistics GetImageStats( double (&pSignalArray)[4])

Thanks for any suggestions; A couple of lines of code will help a lot.

回答1:

I think it should be:

private static double[] _statsArray = new double[4];
GetImageStats(_statsArray); // Lose the ref

And

DllExportImageStatistics GetImageStats(double pSignalArray[4])