/*----------------------------------------------------------------------------
|
| Define pointers
|
-----------------------------------------------------------------------------*/
#ifndef PL_BYTE
#define PL_BYTE uint8_t *
#endif
/*----------------------------------------------------------------------------
|
| Define structs
|
-----------------------------------------------------------------------------*/
typedef struct DEMO_t
{
uint16_t length;
PL_BYTE payLoad; /* 长度取决于 length 的值*/
} DEMO;
# 定义 BL_LPBYTE 类型
BL_LPBYTE = ctypes.POINTER(uint8_t)
class DEMO_DATA(ctypes.Structure):
_fields_ = [
("length", ctypes.c_uint16),
("payLoad", BL_LPBYTE),
]
# 加载 dll
dll = ctypes.CDLL('demo.dll')
# 定义 dll 中的 Read 方法, 其实我也不太懂为什么要这样
dll.Read.argtypes = [ctypes.c_void_p, ctypes.POINTER(DEMO)]
dll.dll.restype = ctypes.c_int32
# 创建文件,数据源
handle = dll.Create('file.target')
# 创建结构体
demo = DEMO()
# 读取数据,正常传入文件以及结构体,dll 会自动像结构体中存入数据
dll.Read(handle,ctypes.byref(demo))
2
NessajCN 345 天前
BL_LPBYTE = ctypes.POINTER(ctypes.c_uint8)
|