Hello, all,
I am trying to wrap an C structure (see below) which has array members
to C#. I am really new to SWIG and I wrote the following type
maps.
****my structure******************
typedef struct {
int a;
int b;
double arr[100];
} test_struct;
****my C# typemap*************************
%typemap(ctype) double *, double[ANY], double[] "double *"
%typemap(imtype) double *, double[ANY], double[] "double []"
%typemap(cstype) double *, double[ANY], double[] "double []"
%typemap(csin) double *, double[ANY], double[] "$csinput"
%typemap(csout, excode=3DSWIGEXCODE) double *, double[ANY], double[] {
double[] ret =3D $imcall;$excode
return ret;
}
%typemap(csvarin, excode=3DSWIGEXCODE2) double *, double[ANY], double[] %{
set {
$imcall;$excode
} %}
%typemap(csvarout, excode=3DSWIGEXCODE2) double *, double[ANY], double[] %{
get {
double[] ret =3D $imcall;$excode
return ret;
} %}
*********************************
And in the generated test_struct.cs, the properties of the array member is:
**************************************
public double [] arr {
set {
mytestPINVOKE.test_struct_arr_set(swigCPtr, value);
}
get {
double[] ret =3D mytestPINVOKE.test_struct_arr_get(swigCPtr);
return ret;
}
}
**************************************
But when I try to access the array from C#, I get:
************************************
Unhandled Exception:
System.Runtime.InteropServices.MarshalDirectiveException: Can not mar
shal return value.
..........
************************************
What am I doing wrong? How should I write the typemaps for this
structure so that I can access the array in C# simething like:
test_struct ts;
double[] csarray=3D ts.arr;
ts.arr =3D csarray; or ts.arr(csarray); etc.
double a1 =3D ts.arr[1];
Any hints/recommendations are very much appreciated! Please help!
Thanks,
Xutuan
|