所以,我正在使用ctypes调用dll函数。我传入了返回变量by_ref()。在代码中,它看起来像:
mydll = cdll('dllpath')
terminal_id = BYTE()
print("terminal id before api call:",terminal_id)
ret = mydll.func(input,byref(terminal_id))
print("terminal id after api call:",terminal_id)
以下代码打印:
terminal id before api call:c_byte(0)
terminal id after api call:c_byte(53)
我有一个GUI,可以从终端ID为:6380491601819081的GUI与终端进行交互
如何从返回的terminal_id变量中提取出来?
您可以使用terminal_id.value
获取值。
[print(dir(terminal_id))
将显示c_byte
类型的属性和方法。
ctypes中的[A c_byte
似乎是C中的char
(ctypes doc)。
import ctypes
x = ctypes.c_byte(3)
print(dir(x))
print(x.value)
6380491601819081不能容纳一个字节。类型不够大。