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
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
33 VOID
= None # FIXME: ctypes has no concept of the void type
34 LPCVOID
= LPVOID
= c_void_p
37 LPBOOL
= PBOOL
= POINTER(BOOL
)
40 LPBYTE
= PBYTE
= POINTER(BYTE
)
43 PUCHAR
= POINTER(UCHAR
)
46 LPWORD
= PWORD
= POINTER(WORD
)
49 PUSHORT
= POINTER(USHORT
)
52 LPINT
= PINT
= POINTER(INT
)
58 PFLOAT
= POINTER(FLOAT
)
63 LPLONG
= PLONG
= POINTER(LONG
)
66 LPDWORD
= PDWORD
= POINTER(DWORD
)
69 PULONG
= POINTER(ULONG
)
71 # typed defined in basetsd.h
76 PINT16
= POINTER(INT16
)
78 PINT32
= POINTER(INT32
)
80 PINT64
= POINTER(INT64
)
82 PUINT8
= POINTER(UINT8
)
84 PUINT16
= POINTER(UINT16
)
86 PUINT32
= POINTER(UINT32
)
88 PUINT64
= POINTER(UINT64
)
90 PLONG32
= POINTER(LONG32
)
92 PULONG32
= POINTER(ULONG32
)
94 PDWORD32
= POINTER(DWORD32
)
96 PLONG64
= POINTER(LONG64
)
98 PULONG64
= POINTER(ULONG64
)
100 PDWORD64
= POINTER(DWORD64
)
103 PINT_PTR
= POINTER(INT_PTR
)
105 PUINT_PTR
= POINTER(UINT_PTR
)
107 PLONG_PTR
= POINTER(LONG_PTR
)
109 PULONG_PTR
= POINTER(ULONG_PTR
)
111 PDWORD_PTR
= POINTER(DWORD_PTR
)
113 MAXINT_PTR
= 0x7fffffff
114 MININT_PTR
= 0x80000000
115 MAXUINT_PTR
= 0xffffffff
118 PHALF_PTR
= POINTER(HALF_PTR
)
120 PUHALF_PTR
= POINTER(UHALF_PTR
)
122 MAXUHALF_PTR
= 0xffff
127 PSSIZE_T
= POINTER(SSIZE_T
)
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
139 PBOOLEAN
= POINTER(BOOLEAN
)
142 PCHAR
= POINTER(CHAR
)
148 PWCHAR
= POINTER(WCHAR
)
151 PLONGLONG
= POINTER(LONGLONG
)
154 PULONGLONG
= POINTER(ULONGLONG
)
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':
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
177 PLCID
= POINTER(LCID
)
181 EXECUTION_STATE
= DWORD
183 # HRESULT = ctypes.HRESULT
186 PHANDLE
= LPHANDLE
= POINTER(HANDLE
)
192 class LUID(Structure
):
197 PLUID
= POINTER(LUID
)
207 LPCOLORREF
= POINTER(DWORD
)
216 HENHMETAFILE
= HANDLE
223 PHKEY
= POINTER(HKEY
)
233 HWINEVENTHOOK
= HANDLE
241 GLOBALHANDLE
= HANDLE
245 FARPROC
= WINFUNCTYPE(INT_PTR
)
246 NEARPROC
= WINFUNCTYPE(INT_PTR
)
247 PROC
= WINFUNCTYPE(INT_PTR
)
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)
268 class SIZE(Structure
):
273 PSIZE
= LPSIZE
= POINTER(SIZE
)
276 PSIZEL
= LPSIZEL
= POINTER(SIZEL
)
278 class POINT(Structure
):
283 PPOINT
= LPPOINT
= POINTER(POINT
)
285 class POINTL(Structure
):
290 PPOINTL
= POINTER(POINTL
)
292 class POINTS(Structure
):
297 PPOINTS
= LPPOINTS
= POINTER(POINTS
)
299 class FILETIME(Structure
):
301 ('dwLowDateTime', DWORD
),
302 ('dwHighDateTime', DWORD
),
304 PFILETIME
= LPFILETIME
= POINTER(FILETIME
)
306 class RECT(Structure
):
313 PRECT
= LPRECT
= LPCRECT
= POINTER(RECT
)
315 class RECTL(Structure
):
322 PRECTL
= LPRECTL
= LPCRECTL
= POINTER(RECTL
)
324 if winlitecfg
.aw
== 'W':
325 from ctypes
import create_unicode_buffer
as create_tchar_buffer
327 from ctypes
import create_string_buffer
as create_tchar_buffer
329 class GUID(Structure
):
330 _fields_
= [("Data1", c_uint32
),
333 ("Data4", c_uint8
* 8)]
335 def __init__(self
, *args
):
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)
344 self
.Data4
[i
+2] = int(part5
[i
*2:i
*2+2], 16)
345 Structure
.__init
__(self
)
347 Structure
.__init
__(self
, *args
)
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
)