1# The most useful windows datatypes 2import ctypes 3 4BYTE = ctypes.c_byte 5WORD = ctypes.c_ushort 6DWORD = ctypes.c_ulong 7 8#UCHAR = ctypes.c_uchar 9CHAR = ctypes.c_char 10WCHAR = ctypes.c_wchar 11UINT = ctypes.c_uint 12INT = ctypes.c_int 13 14DOUBLE = ctypes.c_double 15FLOAT = ctypes.c_float 16 17BOOLEAN = BYTE 18BOOL = ctypes.c_long 19 20class VARIANT_BOOL(ctypes._SimpleCData): 21 _type_ = "v" 22 def __repr__(self): 23 return "%s(%r)" % (self.__class__.__name__, self.value) 24 25ULONG = ctypes.c_ulong 26LONG = ctypes.c_long 27 28USHORT = ctypes.c_ushort 29SHORT = ctypes.c_short 30 31# in the windows header files, these are structures. 32_LARGE_INTEGER = LARGE_INTEGER = ctypes.c_longlong 33_ULARGE_INTEGER = ULARGE_INTEGER = ctypes.c_ulonglong 34 35LPCOLESTR = LPOLESTR = OLESTR = ctypes.c_wchar_p 36LPCWSTR = LPWSTR = ctypes.c_wchar_p 37LPCSTR = LPSTR = ctypes.c_char_p 38LPCVOID = LPVOID = ctypes.c_void_p 39 40# WPARAM is defined as UINT_PTR (unsigned type) 41# LPARAM is defined as LONG_PTR (signed type) 42if ctypes.sizeof(ctypes.c_long) == ctypes.sizeof(ctypes.c_void_p): 43 WPARAM = ctypes.c_ulong 44 LPARAM = ctypes.c_long 45elif ctypes.sizeof(ctypes.c_longlong) == ctypes.sizeof(ctypes.c_void_p): 46 WPARAM = ctypes.c_ulonglong 47 LPARAM = ctypes.c_longlong 48 49ATOM = WORD 50LANGID = WORD 51 52COLORREF = DWORD 53LGRPID = DWORD 54LCTYPE = DWORD 55 56LCID = DWORD 57 58################################################################ 59# HANDLE types 60HANDLE = ctypes.c_void_p # in the header files: void * 61 62HACCEL = HANDLE 63HBITMAP = HANDLE 64HBRUSH = HANDLE 65HCOLORSPACE = HANDLE 66HDC = HANDLE 67HDESK = HANDLE 68HDWP = HANDLE 69HENHMETAFILE = HANDLE 70HFONT = HANDLE 71HGDIOBJ = HANDLE 72HGLOBAL = HANDLE 73HHOOK = HANDLE 74HICON = HANDLE 75HINSTANCE = HANDLE 76HKEY = HANDLE 77HKL = HANDLE 78HLOCAL = HANDLE 79HMENU = HANDLE 80HMETAFILE = HANDLE 81HMODULE = HANDLE 82HMONITOR = HANDLE 83HPALETTE = HANDLE 84HPEN = HANDLE 85HRGN = HANDLE 86HRSRC = HANDLE 87HSTR = HANDLE 88HTASK = HANDLE 89HWINSTA = HANDLE 90HWND = HANDLE 91SC_HANDLE = HANDLE 92SERVICE_STATUS_HANDLE = HANDLE 93 94################################################################ 95# Some important structure definitions 96 97class RECT(ctypes.Structure): 98 _fields_ = [("left", LONG), 99 ("top", LONG), 100 ("right", LONG), 101 ("bottom", LONG)] 102tagRECT = _RECTL = RECTL = RECT 103 104class _SMALL_RECT(ctypes.Structure): 105 _fields_ = [('Left', SHORT), 106 ('Top', SHORT), 107 ('Right', SHORT), 108 ('Bottom', SHORT)] 109SMALL_RECT = _SMALL_RECT 110 111class _COORD(ctypes.Structure): 112 _fields_ = [('X', SHORT), 113 ('Y', SHORT)] 114 115class POINT(ctypes.Structure): 116 _fields_ = [("x", LONG), 117 ("y", LONG)] 118tagPOINT = _POINTL = POINTL = POINT 119 120class SIZE(ctypes.Structure): 121 _fields_ = [("cx", LONG), 122 ("cy", LONG)] 123tagSIZE = SIZEL = SIZE 124 125def RGB(red, green, blue): 126 return red + (green << 8) + (blue << 16) 127 128class FILETIME(ctypes.Structure): 129 _fields_ = [("dwLowDateTime", DWORD), 130 ("dwHighDateTime", DWORD)] 131_FILETIME = FILETIME 132 133class MSG(ctypes.Structure): 134 _fields_ = [("hWnd", HWND), 135 ("message", UINT), 136 ("wParam", WPARAM), 137 ("lParam", LPARAM), 138 ("time", DWORD), 139 ("pt", POINT)] 140tagMSG = MSG 141MAX_PATH = 260 142 143class WIN32_FIND_DATAA(ctypes.Structure): 144 _fields_ = [("dwFileAttributes", DWORD), 145 ("ftCreationTime", FILETIME), 146 ("ftLastAccessTime", FILETIME), 147 ("ftLastWriteTime", FILETIME), 148 ("nFileSizeHigh", DWORD), 149 ("nFileSizeLow", DWORD), 150 ("dwReserved0", DWORD), 151 ("dwReserved1", DWORD), 152 ("cFileName", CHAR * MAX_PATH), 153 ("cAlternateFileName", CHAR * 14)] 154 155class WIN32_FIND_DATAW(ctypes.Structure): 156 _fields_ = [("dwFileAttributes", DWORD), 157 ("ftCreationTime", FILETIME), 158 ("ftLastAccessTime", FILETIME), 159 ("ftLastWriteTime", FILETIME), 160 ("nFileSizeHigh", DWORD), 161 ("nFileSizeLow", DWORD), 162 ("dwReserved0", DWORD), 163 ("dwReserved1", DWORD), 164 ("cFileName", WCHAR * MAX_PATH), 165 ("cAlternateFileName", WCHAR * 14)] 166 167################################################################ 168# Pointer types 169 170LPBOOL = PBOOL = ctypes.POINTER(BOOL) 171PBOOLEAN = ctypes.POINTER(BOOLEAN) 172LPBYTE = PBYTE = ctypes.POINTER(BYTE) 173PCHAR = ctypes.POINTER(CHAR) 174LPCOLORREF = ctypes.POINTER(COLORREF) 175LPDWORD = PDWORD = ctypes.POINTER(DWORD) 176LPFILETIME = PFILETIME = ctypes.POINTER(FILETIME) 177PFLOAT = ctypes.POINTER(FLOAT) 178LPHANDLE = PHANDLE = ctypes.POINTER(HANDLE) 179PHKEY = ctypes.POINTER(HKEY) 180LPHKL = ctypes.POINTER(HKL) 181LPINT = PINT = ctypes.POINTER(INT) 182PLARGE_INTEGER = ctypes.POINTER(LARGE_INTEGER) 183PLCID = ctypes.POINTER(LCID) 184LPLONG = PLONG = ctypes.POINTER(LONG) 185LPMSG = PMSG = ctypes.POINTER(MSG) 186LPPOINT = PPOINT = ctypes.POINTER(POINT) 187PPOINTL = ctypes.POINTER(POINTL) 188LPRECT = PRECT = ctypes.POINTER(RECT) 189LPRECTL = PRECTL = ctypes.POINTER(RECTL) 190LPSC_HANDLE = ctypes.POINTER(SC_HANDLE) 191PSHORT = ctypes.POINTER(SHORT) 192LPSIZE = PSIZE = ctypes.POINTER(SIZE) 193LPSIZEL = PSIZEL = ctypes.POINTER(SIZEL) 194PSMALL_RECT = ctypes.POINTER(SMALL_RECT) 195LPUINT = PUINT = ctypes.POINTER(UINT) 196PULARGE_INTEGER = ctypes.POINTER(ULARGE_INTEGER) 197PULONG = ctypes.POINTER(ULONG) 198PUSHORT = ctypes.POINTER(USHORT) 199PWCHAR = ctypes.POINTER(WCHAR) 200LPWIN32_FIND_DATAA = PWIN32_FIND_DATAA = ctypes.POINTER(WIN32_FIND_DATAA) 201LPWIN32_FIND_DATAW = PWIN32_FIND_DATAW = ctypes.POINTER(WIN32_FIND_DATAW) 202LPWORD = PWORD = ctypes.POINTER(WORD) 203