在python中将int转换为int*
Converting int to int* in python
我们正在使用SWIG与Python一起测试c++ API。c++中的一种方法期望int *
为int fnClicTestIntPtr(int *)
;它只是在返回值上加1。我试图在Python中调用这个方法并测试输出。你能告诉我如何在python中通过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 *
我们必须包含" cpointer "。接口文件中的i "接口(使用SWIG将c++连接到Python)。详细信息请参阅http://www.swig.org/Doc2.0/Library.html#Library
相关文章:
- 是否可以从int转换为enum类类型
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 是什么导致了这种使用三进制而不是短整型的有符号int到无符号int转换
- 将字符串中的 int 转换为字母;
- 主.cpp:18:20:错误:从"int*"转换为"int"会失去精度 [-fa
- 将非常大的 int 转换为双倍,在某些计算机上会损失精度
- 如何将矢量<int>转换为字符数组?
- C++ 无法从 const int* 转换为 const_iterator
- 我不断收到错误 C2440'=':无法从"int *(__cdecl *)(int *,int *,int,int)"转换为"int *
- 如何将 int[4] 转换为 std::array<int,4>?
- 如何将data[i].int转换为vaible
- 将 int 转换为字符串,然后连接另一个变量以创建完整扩展名,然后将其转换为 const_char*
- 将私有矩阵形式 int 转换为双 C++
- 无法将参数 1 从 'int' 转换为 'int &'
- 将 int 转换为字符串后始终得到 0
- isspace 函数的性能警告,从 int 转换为布尔值
- 将大 int 转换为浮点数,而不舍入 c++
- 错误:无法将'uint8* {aka unsigned int*}'转换为"常量emxArray_uint8_T*"?
- 将未签名的INT转换为BCD
- 在 C++ 中将 int 转换为双精度