【发布时间】:2014-08-14 14:24:43
【问题描述】:
我正在尝试为 C .lib 创建一个 C# 包装器,其中包含使用 SWIG 获取 void 指针的函数。
int inputPointExample(void* input);
int outputPointerExample(void* output);
默认情况下 SWIG 不处理 void 指针转换,您必须以某种方式使用类型映射。我找到了这个页面 -> http://www.nickdarnell.com/2011/05/swig-and-a-miss/ 数字 9 说使用以下类型映射来处理 void 指针...
%typemap(ctype) void * "void *"
%typemap(imtype) void * "IntPtr"
%typemap(cstype) void * "IntPtr"
%typemap(csin) void * "$csinput"
%typemap(in) void * %{ $1 = $input; %}
%typemap(out) void * %{ $result = $1; %}
%typemap(csout) void * { return $imcall; }
当我尝试在此函数的 exampleVectorType.cs 中遇到编译错误时...
public IntPtr pData {
set {
examplePINVOKE.ExampleVectorType_pData_set(swigCPtr, value);
}
get {
global::System.IntPtr cPtr = examplePINVOKE.ExampleVectorType_pData_get(swigCPtr);
SWIGTYPE_p_void ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_void(cPtr, false);
return ret; //Compile error occurs here
}
}
我知道了-
Cannot implicitly convert type 'SWIGTYPE_p_void' to 'System.IntPtr'
据我所知,许多其他人也遇到了这个问题,关于如何解决这个问题的例子很少。有人可以帮我吗?
【问题讨论】:
标签: c# c interface wrapper swig