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