add skeleton for variant type support
[pywinlite.git] / windef.py
blob2017274cfda3697a7a6226f6eba40049177c58c1
1 #Copyright (c) 2008 Vincent Povirk
3 #Permission is hereby granted, free of charge, to any person
4 #obtaining a copy of this software and associated documentation
5 #files (the "Software"), to deal in the Software without
6 #restriction, including without limitation the rights to use,
7 #copy, modify, merge, publish, distribute, sublicense, and/or sell
8 #copies of the Software, and to permit persons to whom the
9 #Software is furnished to do so, subject to the following
10 #conditions:
12 #The above copyright notice and this permission notice shall be
13 #included in all copies or substantial portions of the Software.
15 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 #OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 #WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 #FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 #OTHER DEALINGS IN THE SOFTWARE.
24 from ctypes import c_void_p, c_int64, c_uint64, c_int32, c_uint32, c_int16, c_uint16, c_int8, c_uint8, c_float, c_char, c_char_p, c_wchar, c_wchar_p, HRESULT, POINTER, WINFUNCTYPE, Structure, Union, windll
25 import winlitecfg
27 _dll = windll.ntdll
29 NULL = 0
30 FALSE = 0
31 TRUE = 1
33 VOID = None # FIXME: ctypes has no concept of the void type
34 LPCVOID = LPVOID = c_void_p
36 BOOL = c_int32
37 LPBOOL = PBOOL = POINTER(BOOL)
39 BYTE = c_uint8
40 LPBYTE = PBYTE = POINTER(BYTE)
42 UCHAR = c_uint8
43 PUCHAR = POINTER(UCHAR)
45 WORD = c_uint16
46 LPWORD = PWORD = POINTER(WORD)
48 USHORT = c_uint16
49 PUSHORT = POINTER(USHORT)
51 INT = c_int32
52 LPINT = PINT = POINTER(INT)
54 UINT = c_uint32
55 PUINT = POINTER(UINT)
57 FLOAT = c_float
58 PFLOAT = POINTER(FLOAT)
60 PSZ = c_char_p
62 LONG = c_uint32
63 LPLONG = PLONG = POINTER(LONG)
65 DWORD = c_uint32
66 LPDWORD = PDWORD = POINTER(DWORD)
68 ULONG = c_uint32
69 PULONG = POINTER(ULONG)
71 # typed defined in basetsd.h
73 INT8 = c_int8
74 PINT8 = POINTER(INT8)
75 INT16 = c_int16
76 PINT16 = POINTER(INT16)
77 INT32 = c_int32
78 PINT32 = POINTER(INT32)
79 INT64 = c_int64
80 PINT64 = POINTER(INT64)
81 UINT8 = c_uint8
82 PUINT8 = POINTER(UINT8)
83 UINT16 = c_uint16
84 PUINT16 = POINTER(UINT16)
85 UINT32 = c_uint32
86 PUINT32 = POINTER(UINT32)
87 UINT64 = c_uint64
88 PUINT64 = POINTER(UINT64)
89 LONG32 = c_int32
90 PLONG32 = POINTER(LONG32)
91 ULONG32 = c_uint32
92 PULONG32 = POINTER(ULONG32)
93 DWORD32 = c_uint32
94 PDWORD32 = POINTER(DWORD32)
95 LONG64 = c_int64
96 PLONG64 = POINTER(LONG64)
97 ULONG64 = c_uint64
98 PULONG64 = POINTER(ULONG64)
99 DWORD64 = c_uint64
100 PDWORD64 = POINTER(DWORD64)
102 INT_PTR = c_int32
103 PINT_PTR = POINTER(INT_PTR)
104 UINT_PTR = c_uint32
105 PUINT_PTR = POINTER(UINT_PTR)
106 LONG_PTR = c_uint32
107 PLONG_PTR = POINTER(LONG_PTR)
108 ULONG_PTR = c_uint32
109 PULONG_PTR = POINTER(ULONG_PTR)
110 DWORD_PTR = c_uint32
111 PDWORD_PTR = POINTER(DWORD_PTR)
113 MAXINT_PTR = 0x7fffffff
114 MININT_PTR = 0x80000000
115 MAXUINT_PTR = 0xffffffff
117 HALF_PTR = c_int16
118 PHALF_PTR = POINTER(HALF_PTR)
119 UHALF_PTR = c_uint16
120 PUHALF_PTR = POINTER(UHALF_PTR)
122 MAXUHALF_PTR = 0xffff
123 MAXHALF_PTR = 0x7fff
124 MINHALF_PTR = 0x8000
126 SSIZE_T = LONG_PTR
127 PSSIZE_T = POINTER(SSIZE_T)
128 SIZE_T = ULONG_PTR
129 PSIZE_T = POINTER(SIZE_T)
131 KAFFINITY = ULONG_PTR
132 PKAFFINITY = POINTER(KAFFINITY)
134 # types defined in winnt.h
136 PVOID = PVOID64 = c_void_p
138 BOOLEAN = BYTE
139 PBOOLEAN = POINTER(BOOLEAN)
141 CHAR = c_char
142 PCHAR = POINTER(CHAR)
144 SHORT = c_int16
145 PSHORT = c_uint16
147 WCHAR = c_wchar
148 PWCHAR = POINTER(WCHAR)
150 LONGLONG = c_int64
151 PLONGLONG = POINTER(LONGLONG)
153 ULONGLONG = c_uint64
154 PULONGLONG = POINTER(ULONGLONG)
156 DWORDLONG = LONGLONG
157 PDWORDLONG = POINTER(DWORDLONG)
159 PCH = LPCH = PCCH = LPCCH = PSTR = LPSTR = NPSTR = PCSTR = LPCSTR = c_char_p
160 PWCH = LPWCH = PCWCH = LPCWCH = PWSTR = LPWSTR = NPWSTR = PCWSTR = LPCWSTR = c_wchar_p
162 #to define the neutral char/string types we need the aw setting
163 winlitecfg.can_set_aw = False
164 if winlitecfg.aw == 'A':
165 TCHAR = CHAR
166 else:
167 TCHAR = WCHAR
169 PTCHAR = PTSTR = LPTSTR = PCTSTR = LPCTSTR = POINTER(TCHAR)
171 # TEXT is a macro for converting constant strings on windows, but here a string type will do nicely
172 TEXT = LPTSTR
174 CCHAR = c_char
176 LCID = DWORD
177 PLCID = POINTER(LCID)
179 LANGID = WORD
181 EXECUTION_STATE = DWORD
183 # HRESULT = ctypes.HRESULT
185 HANDLE = c_void_p
186 PHANDLE = LPHANDLE = POINTER(HANDLE)
188 FCHAR = BYTE
189 FSHORT = WORD
190 FLONG = DWORD
192 class LUID(Structure):
193 _fields_ = [
194 ('LowPart', DWORD),
195 ('HighPart', LONG),
197 PLUID = POINTER(LUID)
199 #end winnt.h types
201 WPARAM = UINT_PTR
202 LPARAM = LONG_PTR
203 LRESULT = LONG_PTR
205 ATOM = WORD
206 COLORREF = DWORD
207 LPCOLORREF = POINTER(DWORD)
209 HFILE = c_int32
210 HACCEL = HANDLE
211 HBITMAP = HANDLE
212 HBRUSH = HANDLE
213 HCOLORSPACE = HANDLE
214 HDC = HANDLE
215 HDESK = HANDLE
216 HENHMETAFILE = HANDLE
217 HFONT = HANDLE
218 HGLRC = HANDLE
219 HHOOK = HANDLE
220 HICON = HANDLE
221 HINSTANCE = HANDLE
222 HKEY = HANDLE
223 PHKEY = POINTER(HKEY)
224 HKL = HANDLE
225 HMENU = HANDLE
226 HMETAFILE = HANDLE
227 HMONITOR = HANDLE
228 HPALETTE = HANDLE
229 HPEN = HANDLE
230 HRGN = HANDLE
231 HRSRC = HANDLE
232 HTASK = HANDLE
233 HWINEVENTHOOK = HANDLE
234 HWINSTA = HANDLE
235 HWND = HANDLE
237 HMODULE = HINSTANCE
238 HGDIOBJ = HANDLE
239 HGLOBAL = HANDLE
240 HLOCAL = HANDLE
241 GLOBALHANDLE = HANDLE
242 LOCALHANDLE = HANDLE
243 HCURSOR = HICON
245 FARPROC = WINFUNCTYPE(INT_PTR)
246 NEARPROC = WINFUNCTYPE(INT_PTR)
247 PROC = WINFUNCTYPE(INT_PTR)
249 def LOBYTE(w):
250 return w & 0xFF
251 def HIBYTE(w):
252 return (w >> 8)&0xFF
254 def LOWORD(l):
255 return l & 0xFFFF
256 def HIWORD(l):
257 return (l >> 16)&0xFFFF
259 def MAKEWORD(low, high):
260 (low&0xFF) | ((high&0xFF)<<8)
262 def MAKELONG(low, high):
263 (low&0xFFFF) | ((high&0xFFFF)<<16)
265 MAX_PATH = 260
266 HFILE_ERROR = -1
268 class SIZE(Structure):
269 _fields_ = [
270 ('cx', LONG),
271 ('cy', LONG),
273 PSIZE = LPSIZE = POINTER(SIZE)
275 SIZEL = SIZE
276 PSIZEL = LPSIZEL = POINTER(SIZEL)
278 class POINT(Structure):
279 _fields_ = [
280 ('x', LONG),
281 ('y', LONG),
283 PPOINT = LPPOINT = POINTER(POINT)
285 class POINTL(Structure):
286 _fields_ = [
287 ('x', LONG),
288 ('y', LONG),
290 PPOINTL = POINTER(POINTL)
292 class POINTS(Structure):
293 _fields_ = [
294 ('x', SHORT),
295 ('y', SHORT),
297 PPOINTS = LPPOINTS = POINTER(POINTS)
299 class FILETIME(Structure):
300 _fields_ = [
301 ('dwLowDateTime', DWORD),
302 ('dwHighDateTime', DWORD),
304 PFILETIME = LPFILETIME = POINTER(FILETIME)
306 class RECT(Structure):
307 _fields_ = [
308 ('left', LONG),
309 ('top', LONG),
310 ('right', LONG),
311 ('bottom', LONG),
313 PRECT = LPRECT = LPCRECT = POINTER(RECT)
315 class RECTL(Structure):
316 _fields_ = [
317 ('left', LONG),
318 ('top', LONG),
319 ('right', LONG),
320 ('bottom', LONG),
322 PRECTL = LPRECTL = LPCRECTL = POINTER(RECTL)
324 if winlitecfg.aw == 'W':
325 from ctypes import create_unicode_buffer as create_tchar_buffer
326 else:
327 from ctypes import create_string_buffer as create_tchar_buffer
329 class GUID(Structure):
330 _fields_ = [("Data1", c_uint32),
331 ("Data2", c_uint16),
332 ("Data3", c_uint16),
333 ("Data4", c_uint8 * 8)]
335 def __init__(self, *args):
336 if len(args) == 1:
337 part1, part2, part3, part4, part5 = args[0].split('-')
338 self.Data1 = int(part1, 16)
339 self.Data2 = int(part2, 16)
340 self.Data3 = int(part3, 16)
341 self.Data4[0] = int(part4[0:2], 16)
342 self.Data4[1] = int(part4[2:4], 16)
343 for i in range(6):
344 self.Data4[i+2] = int(part5[i*2:i*2+2], 16)
345 Structure.__init__(self)
346 else:
347 Structure.__init__(self, *args)
349 def __str__(self):
350 return '%08x-%04x-%04x-%s' % (int(self.Data1), int(self.Data2), int(self.Data3), '%02x%02x-%02x%02x%02x%02x%02x%02x' % tuple(self.Data4))
352 FMTID = CLSID = IID = GUID
354 REFFMTID = LPFMTID = REFCLSID = REFIID = POINTER(GUID)
356 LPCOLESTR = LPOLESTR = LPWSTR
358 ULARGE_INTEGER = ULONGLONG
360 LARGE_INTEGER = LONGLONG
362 class FILETIME(Structure):
363 _fields_ = [('dwLowDateTime', DWORD),
364 ('dwHighDateTime', DWORD),
367 PFILETIME = POINTER(FILETIME)
369 S_OK = 0
370 S_FALSE = 1
372 OLE_HANDLE = ULONG