0

I can return a number e.g. double from the C++ method written in the C++ DLL into C#

C++ side

__declspec(dllexport) double GetData()
{
    double data = 5;

    return data;
}

C# side

[DllImport("data_acquisition_sys.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern double GetData();
double data = GetData();

But if I want to return an array of doubles double* or double[] like above, just change the return value

__declspec(dllexport) double* GetData()  //C++
public static extern double[] GetData(); //C#

I get the following error

Unhandled Exception: System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'return value': Invalid managed/unmanaged type combination.

pjercic
  • 417
  • 1
  • 7
  • 19

1 Answers1

1

Here you can find an example how to p/invoke arrays from native to managed environment:

Read further about array passing here:

Spook
  • 25,318
  • 18
  • 90
  • 167