We are using SWIG to test C++ API with Python. One of the method in C++ expects int *
as int fnClicTestIntPtr(int *)
; It just adds one at returns value. I am trying to call this method in Python and test the output. Can you please tell me how can i pass int*
in Pyhton.
My interface file looks like this:
%module ClicTest
%{
#include "ClicTest.h"
%}
%include <windows.i>
%include "ClicTest.h"
Header file:
#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 *);
I tried passing a number , also tried using ctypes.byref and ctypes.pointer methods. But nothing has been successfull.Like below
Py file:
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 *
We had to include “cpointer.i” interface in the interface file (connecting C++ to Python using SWIG). Refer to http://www.swig.org/Doc2.0/Library.html#Library for more details
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.