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