ctypes 的 python documentation 显示了使用原型定义和 paramflags 与 windows 函数 GetWindowRect 的示例。
因为 GetWindowRect 有签名
BOOL GetWindowRect(
[in] HWND hWnd,
[out] LPRECT lpRect
);
我们看到有一个input参数hWnd,一个output参数lpRect,以及函数的返回值为BOOL。
文档提供了这个片段
from ctypes import POINTER, WINFUNCTYPE, windll, WinError
from ctypes.wintypes import BOOL, HWND, RECT
prototype = WINFUNCTYPE(BOOL, HWND, POINTER(RECT))
paramflags = (1, "hwnd"), (2, "lprect")
GetWindowRect = prototype(("GetWindowRect", windll.user32), paramflags)
获得一个输入为 hWnd 、输出为 lpRect 的可用函数。引用文档:
如果有一个输出参数,则带有输出参数的函数将自动返回输出参数值;如果有多个输出参数值,则返回包含输出参数值的元组,因此 GetWindowRect 函数现在在调用时返回一个 RECT 实例。
这一切都很好,但是我如何获得函数的原始返回值(在本例中为 BOOL)?这种方法似乎迷失了方向。