开发者

How can I define a typemap for SWIG, that converts a reference argument from C++ to C#

开发者 https://www.devze.com 2023-01-09 21:47 出处:网络
I have a C++ library开发者_Go百科 which provides the following enum and function: typedef enum en{

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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号