投射到ctypes.wintypes

时间:2014-09-11 19:10:59

标签: python ctypes

我的代码:

coord = ctypes.windll.kernel32.GetLargestConsoleWindowSize(console_handle)

coord的真实类型为ctyles.wintypes._COORD但是当我访问它时,它是int

如何将coord投射到ctyles.wintypes._COORD

我尝试了ctyles.wintypes._COORD(coord),但它不起作用。

1 个答案:

答案 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