
各位大佬,有 2 个问题需要请求一下,感激不尽
1、单独的结构体,可以直接用 python 的类来创建,但这结构体里边嵌套了一个枚举,应该怎么创建这种结构体啊
typedef struct { AttrType eType; int nValue; float fScore; }T_Result; typedef enum { A = 0, B = 1, C = 2, D = 3, }AttrType; 2、python 调用 C 函数,遇到二级指针,如何传参数呢?以下我的办法不可用
// C 函数原型, 伪代码: A(IF_UINT8 ** A1) { xx return 0; } typedef unsigned char IF_UINT8;# python 调用 dll = CDLL("test.dll") dll.A.argtypes = [POINTER(POINTER(c_ubyte))] args= POINTER(c_ubyte)() dll.A(byref(args)) # 这样报错:OSError: exception: access violation reading 0x0000000000000004
1 ysc3839 2019 年 2 月 20 日 via Android 1. 试试直接用 int 2. 需要代码才知道具体该怎么办 |
2 dinjufen 2019 年 2 月 20 日 C 代码: // dll1.h #pragma once #define EXPT __declspec(dllexport) extern "C" { EXPT void A(int** arg); } // dll1.cpp #include "stdafx.h" #include "Dll1.h" void A(int** arg) { printf("arg = %d", **arg); } Python 代码: from ctypes import cdll from ctypes import POINTER, cast from ctypes import c_int dll = cdll.LoadLibrary("Dll1.dll") dll.A.argtypes = [POINTER(POINTER(c_int))] p_x = POINTER(c_int) List_int = [(5,)] List = (c_int*1*1)(*List_int) List_p = [] List_p.append(cast(List[0], p_x)) p2ci = (p_x*1)(*List_p) # 调用 dll.A(p2ci) PS: 我也是查找资料才找到类似的, 以上代码可运行成功 |
3 aihimmel 2019 年 2 月 20 日 |
7 aihimmel 2019 年 2 月 20 日 |