如何传递整型数组和列表<;字符串>;作为C+的参数+;使用SWIG时从C# 使用SWIG,需要将列表和int数组作为参数传递给C++函数。我尝试了以下代码
''”CPP接口代码如何传递整型数组和列表<;字符串>;作为C+的参数+;使用SWIG时从C# 使用SWIG,需要将列表和int数组作为参数传递给C++函数。我尝试了以下代码,c#,c++,swig,C#,C++,Swig,''”CPP接口代码 %模块(directors=“1”)CppTestApp %{ #包括“TestClass.h” #包括“TestDataClass.h” %} %包括 %包括 %包括 %包括“数组\u csharp.i” %特写(“导演”)基地; %包括“TestClass.h” %包括“TestDataClass.h” ''' 但是我得到的参数是SWIGTYPE\u p\u std\u listT\u std\u string\u t和SWIGTYPE\u p\u double我无法
%模块(directors=“1”)CppTestApp
%{
#包括“TestClass.h”
#包括“TestDataClass.h”
%}
%包括
%包括
%包括
%包括“数组\u csharp.i”
%特写(“导演”)基地;
%包括“TestClass.h”
%包括“TestDataClass.h”
'''
但是我得到的参数是SWIGTYPE\u p\u std\u listT\u std\u string\u t和SWIGTYPE\u p\u double我无法将List分配给上述变量。有人能帮助解决这个问题吗? < P>我得到了一个答案,如何通过Cig将C数组传递到C++。请看下面 ''SWIG接口代码
%module (directors="1") CppTestApp
%{
#include "TestClass.h"
#include "TestDataClass.h"
%}
%include <windows.i>
%include <std_string.i>
%include <arrays_csharp.i>
CSHARP_ARRAYS(char *, string)
%typemap(imtype, inattributes="[In, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0, ArraySubType=UnmanagedType.LPStr)]") char * INPUT[] "string[]"
%apply char * INPUT[] { char * argv [], char * argvqq [] }
%apply int INPUT[] { int sourceArray [] }
%apply double INPUT[] { double sourcedoubleArray [] }
%apply char INPUT[] { char chArray [] }
%apply bool INPUT[] { bool bArray [] }
%apply long INPUT[] { long lArray [] }
%apply float INPUT[] { float fArray [] }
%feature("director") Base;
%include "TestClass.h"
%include "TestDataClass.h"
'''
''生成的SWIG C#代码
'''
%module (directors="1") CppTestApp
%{
#include "TestClass.h"
#include "TestDataClass.h"
%}
%include <windows.i>
%include <std_string.i>
%include <arrays_csharp.i>
CSHARP_ARRAYS(char *, string)
%typemap(imtype, inattributes="[In, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0, ArraySubType=UnmanagedType.LPStr)]") char * INPUT[] "string[]"
%apply char * INPUT[] { char * argv [], char * argvqq [] }
%apply int INPUT[] { int sourceArray [] }
%apply double INPUT[] { double sourcedoubleArray [] }
%apply char INPUT[] { char chArray [] }
%apply bool INPUT[] { bool bArray [] }
%apply long INPUT[] { long lArray [] }
%apply float INPUT[] { float fArray [] }
%feature("director") Base;
%include "TestClass.h"
%include "TestDataClass.h"
class TestClass
{
public:
int times2(int sourceArray[], double sourcedoubleArray[], char* argv[], char chArray[], bool bArray[], float fArray[], long lArray[]);
};
[global::System.Runtime.InteropServices.DllImport("CppTestApp", EntryPoint="CSharp_TestClass_times2")]
public static extern int TestClass_times2(global::System.Runtime.InteropServices.HandleRef jarg1, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]int[] jarg2, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]double[] jarg3, [In, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0, ArraySubType=UnmanagedType.LPStr)]string[] jarg4, string jarg5, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray,ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]bool[] jarg6, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]float[] jarg7, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]int[] jarg8);