C# passing double array to C++ dll

橙三吉。 提交于 2019-12-13 04:07: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])


来源:https://stackoverflow.com/questions/15339922/c-sharp-passing-double-array-to-c-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!