How can I define a typemap for SWIG, that converts a reference argument from C++ to C#
I have a C++ library开发者_Go百科 which provides the following enum and function:
typedef enum en{
a,
b
}myEnum;
int myFunction( myEnum &varToSet )
{
varToSet = 1;
return 0;
}
The function in the C# Wrapper should look something like this:
public static int myFunction( ref myEnum varToSet )
I have tried to get this result by following typemap in the Swig interface file:
%typemap(cstype) myEnum & "ref myEnum"
%typemap(csin) myEnum & %{ref $csinput%}
Swig changed the type from SWIGTYPE_p_myEnum to ref myEnum in Wrapper.cs, but not in WrapperPINVOKE.cs. What am I missing here?
You need to add a typemap for imtype:
%typemap(imtype) myEnum & "ref myEnum"
精彩评论