我们使用SWIG测试Python的C++ API。C++中的一个方法希望^ {< CD1> }
int fnClicTestIntPtr(int *)
;它只在返回值处加一个。我尝试在Python中调用这个方法并测试输出。你能告诉我怎样才能通过Pyhton的int*
吗。你知道吗
我的接口文件如下所示:
%module ClicTest
%{
#include "ClicTest.h"
%}
%include <windows.i>
%include "ClicTest.h"
头文件:
#ifdef CLICTEST_EXPORTS
#define CLICTEST_API __declspec(dllexport)
#else
#define CLICTEST_API __declspec(dllimport)
#endif
// This class is exported from the ClicTest.dll
class CLICTEST_API CClicTest {
public:
CClicTest(void);
// TODO: add your methods here.
};
extern CLICTEST_API int nClicTest;
CLICTEST_API int fnClicTest(void);
CLICTEST_API int fnClicTestInt(int);
CLICTEST_API char* fnClicTestChar(char *);
CLICTEST_API int fnClicTestIntPtr(int *);
CLICTEST_API int fnClicTestVoidPtr(void *);
CLICTEST_API char* fnClicTestCharPtr(char *);
CLICTEST_API long fnClicTestLongPtr(long *);
我试着传递一个号码,也试着使用ctypes.byref类型以及ctypes.指针方法。但什么都没有成功了。就像下面
Py文件:
print(ClicTest.fnClicTestLongPtr(ctypes.pointer(num)))
print(ClicTest.fnClicTestLongPtr(num))
print(ClicTest.fnClicTestLongPtr(ctypes.byref(num)))
-
Error : TypeError: in method 'fnClicTestIntPtr', argument 1 of type 'int *
我们必须在接口文件中包括“cPosi.I”接口(使用SWIG将C++连接到Python)。有关详细信息,请参阅http://www.swig.org/Doc2.0/Library.html#Library
相关问题 更多 >
编程相关推荐