mirror of https://github.com/python/cpython
Issue #3612: Added new types to ctypes.wintypes. (CHAR and pointers)
This commit is contained in:
parent
7405c200bb
commit
cc868d430b
|
@ -1,49 +1,50 @@
|
||||||
# The most useful windows datatypes
|
# The most useful windows datatypes
|
||||||
from ctypes import *
|
import ctypes
|
||||||
|
|
||||||
BYTE = c_byte
|
BYTE = ctypes.c_byte
|
||||||
WORD = c_ushort
|
WORD = ctypes.c_ushort
|
||||||
DWORD = c_ulong
|
DWORD = ctypes.c_ulong
|
||||||
|
|
||||||
WCHAR = c_wchar
|
#UCHAR = ctypes.c_uchar
|
||||||
UINT = c_uint
|
CHAR = ctypes.c_char
|
||||||
INT = c_int
|
WCHAR = ctypes.c_wchar
|
||||||
|
UINT = ctypes.c_uint
|
||||||
|
INT = ctypes.c_int
|
||||||
|
|
||||||
DOUBLE = c_double
|
DOUBLE = ctypes.c_double
|
||||||
FLOAT = c_float
|
FLOAT = ctypes.c_float
|
||||||
|
|
||||||
BOOLEAN = BYTE
|
BOOLEAN = BYTE
|
||||||
BOOL = c_long
|
BOOL = ctypes.c_long
|
||||||
|
|
||||||
from ctypes import _SimpleCData
|
class VARIANT_BOOL(ctypes._SimpleCData):
|
||||||
class VARIANT_BOOL(_SimpleCData):
|
|
||||||
_type_ = "v"
|
_type_ = "v"
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%s(%r)" % (self.__class__.__name__, self.value)
|
return "%s(%r)" % (self.__class__.__name__, self.value)
|
||||||
|
|
||||||
ULONG = c_ulong
|
ULONG = ctypes.c_ulong
|
||||||
LONG = c_long
|
LONG = ctypes.c_long
|
||||||
|
|
||||||
USHORT = c_ushort
|
USHORT = ctypes.c_ushort
|
||||||
SHORT = c_short
|
SHORT = ctypes.c_short
|
||||||
|
|
||||||
# in the windows header files, these are structures.
|
# in the windows header files, these are structures.
|
||||||
_LARGE_INTEGER = LARGE_INTEGER = c_longlong
|
_LARGE_INTEGER = LARGE_INTEGER = ctypes.c_longlong
|
||||||
_ULARGE_INTEGER = ULARGE_INTEGER = c_ulonglong
|
_ULARGE_INTEGER = ULARGE_INTEGER = ctypes.c_ulonglong
|
||||||
|
|
||||||
LPCOLESTR = LPOLESTR = OLESTR = c_wchar_p
|
LPCOLESTR = LPOLESTR = OLESTR = ctypes.c_wchar_p
|
||||||
LPCWSTR = LPWSTR = c_wchar_p
|
LPCWSTR = LPWSTR = ctypes.c_wchar_p
|
||||||
LPCSTR = LPSTR = c_char_p
|
LPCSTR = LPSTR = ctypes.c_char_p
|
||||||
LPCVOID = LPVOID = c_void_p
|
LPCVOID = LPVOID = ctypes.c_void_p
|
||||||
|
|
||||||
# WPARAM is defined as UINT_PTR (unsigned type)
|
# WPARAM is defined as UINT_PTR (unsigned type)
|
||||||
# LPARAM is defined as LONG_PTR (signed type)
|
# LPARAM is defined as LONG_PTR (signed type)
|
||||||
if sizeof(c_long) == sizeof(c_void_p):
|
if ctypes.sizeof(ctypes.c_long) == ctypes.sizeof(ctypes.c_void_p):
|
||||||
WPARAM = c_ulong
|
WPARAM = ctypes.c_ulong
|
||||||
LPARAM = c_long
|
LPARAM = ctypes.c_long
|
||||||
elif sizeof(c_longlong) == sizeof(c_void_p):
|
elif ctypes.sizeof(ctypes.c_longlong) == ctypes.sizeof(ctypes.c_void_p):
|
||||||
WPARAM = c_ulonglong
|
WPARAM = ctypes.c_ulonglong
|
||||||
LPARAM = c_longlong
|
LPARAM = ctypes.c_longlong
|
||||||
|
|
||||||
ATOM = WORD
|
ATOM = WORD
|
||||||
LANGID = WORD
|
LANGID = WORD
|
||||||
|
@ -56,7 +57,7 @@ LCID = DWORD
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# HANDLE types
|
# HANDLE types
|
||||||
HANDLE = c_void_p # in the header files: void *
|
HANDLE = ctypes.c_void_p # in the header files: void *
|
||||||
|
|
||||||
HACCEL = HANDLE
|
HACCEL = HANDLE
|
||||||
HBITMAP = HANDLE
|
HBITMAP = HANDLE
|
||||||
|
@ -93,45 +94,45 @@ SERVICE_STATUS_HANDLE = HANDLE
|
||||||
################################################################
|
################################################################
|
||||||
# Some important structure definitions
|
# Some important structure definitions
|
||||||
|
|
||||||
class RECT(Structure):
|
class RECT(ctypes.Structure):
|
||||||
_fields_ = [("left", c_long),
|
_fields_ = [("left", LONG),
|
||||||
("top", c_long),
|
("top", LONG),
|
||||||
("right", c_long),
|
("right", LONG),
|
||||||
("bottom", c_long)]
|
("bottom", LONG)]
|
||||||
tagRECT = _RECTL = RECTL = RECT
|
tagRECT = _RECTL = RECTL = RECT
|
||||||
|
|
||||||
class _SMALL_RECT(Structure):
|
class _SMALL_RECT(ctypes.Structure):
|
||||||
_fields_ = [('Left', c_short),
|
_fields_ = [('Left', SHORT),
|
||||||
('Top', c_short),
|
('Top', SHORT),
|
||||||
('Right', c_short),
|
('Right', SHORT),
|
||||||
('Bottom', c_short)]
|
('Bottom', SHORT)]
|
||||||
SMALL_RECT = _SMALL_RECT
|
SMALL_RECT = _SMALL_RECT
|
||||||
|
|
||||||
class _COORD(Structure):
|
class _COORD(ctypes.Structure):
|
||||||
_fields_ = [('X', c_short),
|
_fields_ = [('X', SHORT),
|
||||||
('Y', c_short)]
|
('Y', SHORT)]
|
||||||
|
|
||||||
class POINT(Structure):
|
class POINT(ctypes.Structure):
|
||||||
_fields_ = [("x", c_long),
|
_fields_ = [("x", LONG),
|
||||||
("y", c_long)]
|
("y", LONG)]
|
||||||
tagPOINT = _POINTL = POINTL = POINT
|
tagPOINT = _POINTL = POINTL = POINT
|
||||||
|
|
||||||
class SIZE(Structure):
|
class SIZE(ctypes.Structure):
|
||||||
_fields_ = [("cx", c_long),
|
_fields_ = [("cx", LONG),
|
||||||
("cy", c_long)]
|
("cy", LONG)]
|
||||||
tagSIZE = SIZEL = SIZE
|
tagSIZE = SIZEL = SIZE
|
||||||
|
|
||||||
def RGB(red, green, blue):
|
def RGB(red, green, blue):
|
||||||
return red + (green << 8) + (blue << 16)
|
return red + (green << 8) + (blue << 16)
|
||||||
|
|
||||||
class FILETIME(Structure):
|
class FILETIME(ctypes.Structure):
|
||||||
_fields_ = [("dwLowDateTime", DWORD),
|
_fields_ = [("dwLowDateTime", DWORD),
|
||||||
("dwHighDateTime", DWORD)]
|
("dwHighDateTime", DWORD)]
|
||||||
_FILETIME = FILETIME
|
_FILETIME = FILETIME
|
||||||
|
|
||||||
class MSG(Structure):
|
class MSG(ctypes.Structure):
|
||||||
_fields_ = [("hWnd", HWND),
|
_fields_ = [("hWnd", HWND),
|
||||||
("message", c_uint),
|
("message", UINT),
|
||||||
("wParam", WPARAM),
|
("wParam", WPARAM),
|
||||||
("lParam", LPARAM),
|
("lParam", LPARAM),
|
||||||
("time", DWORD),
|
("time", DWORD),
|
||||||
|
@ -139,7 +140,7 @@ class MSG(Structure):
|
||||||
tagMSG = MSG
|
tagMSG = MSG
|
||||||
MAX_PATH = 260
|
MAX_PATH = 260
|
||||||
|
|
||||||
class WIN32_FIND_DATAA(Structure):
|
class WIN32_FIND_DATAA(ctypes.Structure):
|
||||||
_fields_ = [("dwFileAttributes", DWORD),
|
_fields_ = [("dwFileAttributes", DWORD),
|
||||||
("ftCreationTime", FILETIME),
|
("ftCreationTime", FILETIME),
|
||||||
("ftLastAccessTime", FILETIME),
|
("ftLastAccessTime", FILETIME),
|
||||||
|
@ -148,10 +149,10 @@ class WIN32_FIND_DATAA(Structure):
|
||||||
("nFileSizeLow", DWORD),
|
("nFileSizeLow", DWORD),
|
||||||
("dwReserved0", DWORD),
|
("dwReserved0", DWORD),
|
||||||
("dwReserved1", DWORD),
|
("dwReserved1", DWORD),
|
||||||
("cFileName", c_char * MAX_PATH),
|
("cFileName", CHAR * MAX_PATH),
|
||||||
("cAlternateFileName", c_char * 14)]
|
("cAlternateFileName", CHAR * 14)]
|
||||||
|
|
||||||
class WIN32_FIND_DATAW(Structure):
|
class WIN32_FIND_DATAW(ctypes.Structure):
|
||||||
_fields_ = [("dwFileAttributes", DWORD),
|
_fields_ = [("dwFileAttributes", DWORD),
|
||||||
("ftCreationTime", FILETIME),
|
("ftCreationTime", FILETIME),
|
||||||
("ftLastAccessTime", FILETIME),
|
("ftLastAccessTime", FILETIME),
|
||||||
|
@ -160,22 +161,42 @@ class WIN32_FIND_DATAW(Structure):
|
||||||
("nFileSizeLow", DWORD),
|
("nFileSizeLow", DWORD),
|
||||||
("dwReserved0", DWORD),
|
("dwReserved0", DWORD),
|
||||||
("dwReserved1", DWORD),
|
("dwReserved1", DWORD),
|
||||||
("cFileName", c_wchar * MAX_PATH),
|
("cFileName", WCHAR * MAX_PATH),
|
||||||
("cAlternateFileName", c_wchar * 14)]
|
("cAlternateFileName", WCHAR * 14)]
|
||||||
|
|
||||||
__all__ = ['ATOM', 'BOOL', 'BOOLEAN', 'BYTE', 'COLORREF', 'DOUBLE', 'DWORD',
|
################################################################
|
||||||
'FILETIME', 'FLOAT', 'HACCEL', 'HANDLE', 'HBITMAP', 'HBRUSH',
|
# Pointer types
|
||||||
'HCOLORSPACE', 'HDC', 'HDESK', 'HDWP', 'HENHMETAFILE', 'HFONT',
|
|
||||||
'HGDIOBJ', 'HGLOBAL', 'HHOOK', 'HICON', 'HINSTANCE', 'HKEY',
|
LPBOOL = PBOOL = ctypes.POINTER(BOOL)
|
||||||
'HKL', 'HLOCAL', 'HMENU', 'HMETAFILE', 'HMODULE', 'HMONITOR',
|
PBOOLEAN = ctypes.POINTER(BOOLEAN)
|
||||||
'HPALETTE', 'HPEN', 'HRGN', 'HRSRC', 'HSTR', 'HTASK', 'HWINSTA',
|
LPBYTE = PBYTE = ctypes.POINTER(BYTE)
|
||||||
'HWND', 'INT', 'LANGID', 'LARGE_INTEGER', 'LCID', 'LCTYPE',
|
PCHAR = ctypes.POINTER(CHAR)
|
||||||
'LGRPID', 'LONG', 'LPARAM', 'LPCOLESTR', 'LPCSTR', 'LPCVOID',
|
LPCOLORREF = ctypes.POINTER(COLORREF)
|
||||||
'LPCWSTR', 'LPOLESTR', 'LPSTR', 'LPVOID', 'LPWSTR', 'MAX_PATH',
|
LPDWORD = PDWORD = ctypes.POINTER(DWORD)
|
||||||
'MSG', 'OLESTR', 'POINT', 'POINTL', 'RECT', 'RECTL', 'RGB',
|
LPFILETIME = PFILETIME = ctypes.POINTER(FILETIME)
|
||||||
'SC_HANDLE', 'SERVICE_STATUS_HANDLE', 'SHORT', 'SIZE', 'SIZEL',
|
PFLOAT = ctypes.POINTER(FLOAT)
|
||||||
'SMALL_RECT', 'UINT', 'ULARGE_INTEGER', 'ULONG', 'USHORT',
|
LPHANDLE = PHANDLE = ctypes.POINTER(HANDLE)
|
||||||
'VARIANT_BOOL', 'WCHAR', 'WIN32_FIND_DATAA', 'WIN32_FIND_DATAW',
|
PHKEY = ctypes.POINTER(HKEY)
|
||||||
'WORD', 'WPARAM', '_COORD', '_FILETIME', '_LARGE_INTEGER',
|
LPHKL = ctypes.POINTER(HKL)
|
||||||
'_POINTL', '_RECTL', '_SMALL_RECT', '_ULARGE_INTEGER', 'tagMSG',
|
LPINT = PINT = ctypes.POINTER(INT)
|
||||||
'tagPOINT', 'tagRECT', 'tagSIZE']
|
PLARGE_INTEGER = ctypes.POINTER(LARGE_INTEGER)
|
||||||
|
PLCID = ctypes.POINTER(LCID)
|
||||||
|
LPLONG = PLONG = ctypes.POINTER(LONG)
|
||||||
|
LPMSG = PMSG = ctypes.POINTER(MSG)
|
||||||
|
LPPOINT = PPOINT = ctypes.POINTER(POINT)
|
||||||
|
PPOINTL = ctypes.POINTER(POINTL)
|
||||||
|
LPRECT = PRECT = ctypes.POINTER(RECT)
|
||||||
|
LPRECTL = PRECTL = ctypes.POINTER(RECTL)
|
||||||
|
LPSC_HANDLE = ctypes.POINTER(SC_HANDLE)
|
||||||
|
PSHORT = ctypes.POINTER(SHORT)
|
||||||
|
LPSIZE = PSIZE = ctypes.POINTER(SIZE)
|
||||||
|
LPSIZEL = PSIZEL = ctypes.POINTER(SIZEL)
|
||||||
|
PSMALL_RECT = ctypes.POINTER(SMALL_RECT)
|
||||||
|
LPUINT = PUINT = ctypes.POINTER(UINT)
|
||||||
|
PULARGE_INTEGER = ctypes.POINTER(ULARGE_INTEGER)
|
||||||
|
PULONG = ctypes.POINTER(ULONG)
|
||||||
|
PUSHORT = ctypes.POINTER(USHORT)
|
||||||
|
PWCHAR = ctypes.POINTER(WCHAR)
|
||||||
|
LPWIN32_FIND_DATAA = PWIN32_FIND_DATAA = ctypes.POINTER(WIN32_FIND_DATAA)
|
||||||
|
LPWIN32_FIND_DATAW = PWIN32_FIND_DATAW = ctypes.POINTER(WIN32_FIND_DATAW)
|
||||||
|
LPWORD = PWORD = ctypes.POINTER(WORD)
|
||||||
|
|
|
@ -74,6 +74,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #3612: Added new types to ctypes.wintypes. (CHAR and pointers)
|
||||||
|
|
||||||
- Issue #9950: Fix socket.sendall() crash or misbehaviour when a signal is
|
- Issue #9950: Fix socket.sendall() crash or misbehaviour when a signal is
|
||||||
received. Now sendall() properly calls signal handlers if necessary,
|
received. Now sendall() properly calls signal handlers if necessary,
|
||||||
and retries sending if these returned successfully, including on sockets
|
and retries sending if these returned successfully, including on sockets
|
||||||
|
|
Loading…
Reference in New Issue