在python中将int转换为int*

2024-03-28 23:02:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我们使用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 *

Tags: 文件方法apiincludectypesnumintprint