我的代码:
coord = ctypes.windll.kernel32.GetLargestConsoleWindowSize(console_handle)
coord
的真实类型为ctyles.wintypes._COORD
但是当我访问它时,它是int
。
如何将coord
投射到ctyles.wintypes._COORD
?
我尝试了ctyles.wintypes._COORD(coord)
,但它不起作用。
答案 0 :(得分:1)
根据this mailing list post,您可以设置restype
功能的GetLargestConsoleWindowSize
属性。这似乎适用于我的设置,但我不确定它可能具有的其他含义。链接的帖子暗示结构返回值不受官方支持,因此请小心使用。
>>> import ctypes
>>> import ctypes.wintypes
>>>
>>> ctypes.windll.kernel32.GetLargestConsoleWindowSize.restype = ctypes.wintypes._COORD
>>> coord = ctypes.windll.kernel32.GetLargestConsoleWindowSize(ctypes.windll.kernel32.GetStdHandle(-11))
>>> print(type(coord))
<class 'ctypes.wintypes._COORD'>
>>> print(coord.X, coord.Y)
160 81