I'm attempt to call a C++ dll with a struct and function like
struct some_data{
int size,degree,df,order;
double *x,*y,lambda;
};
extern "C"{
__declspec(dllexport) double *some_func(some_data*);
}
from C#:
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct SOME_DATA
{
public int size;
public int degree;
public int df;
public int order;
public System.IntPtr x;
public System.IntPtr y;
public double lambda;
}
[System.Runtime.InteropServices.DllImportAttribute("mydll.dll",EntryPoint="some_func")]
public static extern System.IntPtr some_func(ref SOME_DATA someData);
public IntPtr some_funcCall(){
double[] x = new double[] { 4, 4, 7, 7 };
double[] y = new double[] { 2, 10, 4, 22 };
SOME_DATA someData = new SOME_DATA();
someData.x = Marshal.AllocHGlobal(x.Length * Marshal.SizeOf(typeof(double)));
Marshal.Copy(x, 0, someData.x, x.Length);
someData.y = Marshal.AllocHGlobal(y.Length * Marshal.SizeOf(typeof(double)));
Marshal.Copy(y, 0, someData.y, y.Length);
someData.size = 50;
someData.degree = 3;
someData.df = 50;
someData.order = 4;
someData.lambda = 1;
return some_func(ref someData);
}
I thought I was pretty dang close, but when I run this, the program just quits at the return statement.
Any ideas where I've gone wrong?
Thanks,
Mark