为什么Python2.7符号扩展了x64上从GetDC()返回的HDC?

为什么Python2.7符号扩展了x64上从GetDC()返回的HDC?,python,64-bit,windows-7-x64,cython,Python,64 Bit,Windows 7 X64,Cython,在Python 2.7.5(默认值,2013年5月15日,22:44:16)[MSC v.1500 64位(AMD64)]上,GetDC()的返回值为什么扩展了 from ctypes import * hDC1 = windll.user32.GetDC(None) print hex(hDC1), hDC1, type(hDC1) hDC2 = windll.user32.GetDC(None) print hex(hDC2), hDC2, type(hDC2) 这有时会导致负返回值:

在Python 2.7.5(默认值,2013年5月15日,22:44:16)[MSC v.1500 64位(AMD64)]上,GetDC()的返回值为什么扩展了

from ctypes import *
hDC1 = windll.user32.GetDC(None)
print hex(hDC1), hDC1, type(hDC1)
hDC2 = windll.user32.GetDC(None)
print hex(hDC2), hDC2, type(hDC2)
这有时会导致负返回值:

 0x6a0116c1  1778456257 <type 'int'>   # OK
-0x53fed994 -1409210772 <type 'int'>   # Why negative?

在模块的开头,为每个GDI库函数定义了restype,似乎已经解决了这个问题。

ctypes假设函数返回带符号的int,除非您告诉它。将函数restype设置为无符号值:

from ctypes import *
windll.user32.GetDC.restype = c_void_p
hDC1 = windll.user32.GetDC(None)

ctypes对参数和返回值一无所知,只知道函数的入口点。在cython中,我们发现HANDLE=ctypes.c\u void\u p HDC=HANDLE,但Pyglet实现了Pyglet/libs/win32/init.py\u user32.GetDC.restype=HDC\u user32.GetDC.argtypes=[HWND]中的GetDC(),这是谁的错误?啊,是的,我已经很久没有使用句柄了(微软将它们定义为PVOID)。我尝试了
c\u void\u p
,它对我有效,因此我将更改答案。pyglet定义也应该适用。pyglet初始化重新类型之前是否使用GetDC?在Microsoft数据类型世界中,句柄是PVOID,HDC和HWND都是句柄。pyglet的定义在我看来是正确的(HWND进入,HDC出来)。同意,pyglet的定义看起来是正确的,这就是为什么我如此困惑的原因。Pyglet中的hDC仍然会恢复!真奇怪。也许是其他模块搞砸了。散布一些
print windle.user32.GetDC.restype
语句会很有趣。
from ctypes import *
windll.user32.GetDC.restype = c_void_p
hDC1 = windll.user32.GetDC(None)