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