如何转换或从ctypes.c_byte中获取确切的值

问题描述 投票:1回答:2

所以,我正在使用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变量中提取出来?

python ctypes
2个回答
0
投票

您可以使用terminal_id.value获取值。

[print(dir(terminal_id))将显示c_byte类型的属性和方法。

ctypes中的[A c_byte似乎是C中的charctypes doc)。

import ctypes
x = ctypes.c_byte(3)
print(dir(x))
print(x.value)

0
投票

6380491601819081不能容纳一个字节。类型不够大。

© www.soinside.com 2019 - 2024. All rights reserved.