From: David P. <dpi...@me...> - 2012-05-25 17:36:16
|
> In my c++ project most of the functions having pointers as input like int* , > float * ,double * ,As CSharp doesn't support pointers and passing pointers to > function in c+ means parameter must returning value in its out parameter . > > so to make pointer as out , i typecast the pointers using following code in my > interface file. > > %define INOUT_TYPEMAP(TYPE, CTYPE, CSTYPE, TYPECHECKPRECEDENCE) > > %typemap(ctype) TYPE *, TYPE & "CTYPE *" > %typemap(imtype) TYPE *, TYPE & "out CSTYPE" > %typemap(cstype) TYPE *, TYPE & "out CSTYPE" > %typemap(csin) TYPE *, TYPE & "out $csinput" > %typemap(in) TYPE *, TYPE & > %{ $1 = ($1_ltype)$input; %} > > %typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *INOUT, > TYPE &INOUT "" > %enddef .... > After all this changes my pointers is now converted into out as parameter . > > But if my C++ function is like > > int* Function(int* a ,int b); > > then generated C# function will become > > out int Function(out int a, int b) ..............return parameter also becomes out > and this is not a legal statement in c#. You need to use the "out" attribute of the "cstype" and "imtype" typemaps: %typemap(imtype, out="CSTYPE") TYPE *, TYPE & "out CSTYPE" %typemap(cstype, out="CSTYPE") TYPE *, TYPE & "out CSTYPE" Also, you may find the attached document helpful. |