Nick Tsui
Nick Tsui

Reputation: 634

C# passing double array to C++ dll

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.

Upvotes: 0

Views: 3778

Answers (1)

Matthew Watson
Matthew Watson

Reputation: 109567

I think it should be:

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

And

DllExportImageStatistics GetImageStats(double pSignalArray[4])

Upvotes: 2

Related Questions