簡體   English   中英

在python中將int轉換為int *

[英]Converting int to int* in python

我們正在使用SWIG使用Python測試C ++ API。 C ++中的一種方法期望int *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.pointer方法。 但是沒有成功。

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 *

我們必須在接口文件中包含“ cpointer.i”接口(使用SWIG將C ++連接到Python)。 有關更多詳細信息,請參閱http://www.swig.org/Doc2.0/Library.html#Library

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM