Im making a c# program to plot a cubic spline calculated in c, this is the interop part of the program
my c# code:
[DllImport(@"..\..\..\Debug\Spline_Core.dll")]
static extern IntPtr mult_points(Point[] points, int points_count, double factor);
public Form1()
{
InitializeComponent();
var points = new[]
{
new Point { x = 2, y = 3 },
new Point { x = 5, y = 7 },
};
var sum = mult_points(points, 2, 2);
var mult = (Point[])Marshal.PtrToStructure(sum, typeof(Point[]));
}
and the c code:
typedef struct point
{
double x, y;
} Point;
extern __declspec(dllexport) Point* __stdcall mult_points(Point* points, int points_count, double factor)
{
int i;
Point* mult_points = (Point*)malloc(points_count * sizeof(Point));
for (i = 0; i < points_count; i++)
mult_points[i] = create_point(points[i].x * factor, points[i].y * factor);
return mult_points;
}
I can pass the array of points through the parameters from c# to c, but i can't get it back.