1 ##########################################################################
3 # Copyright 2008-2009 VMware, Inc.
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 ##########################################################################/
30 SHORT = Intrinsic("SHORT", "%i")
31 USHORT = Intrinsic("USHORT", "%u")
32 INT = Intrinsic("INT", "%i")
33 UINT = Intrinsic("UINT", "%u")
34 LONG = Intrinsic("LONG", "%li")
35 ULONG = Intrinsic("ULONG", "%lu")
36 FLOAT = Intrinsic("FLOAT", "%f")
38 INT32 = Intrinsic("INT32", "%i")
39 UINT32 = Intrinsic("UINT32", "%i")
41 BYTE = Intrinsic("BYTE", "0x%02lx")
42 WORD = Intrinsic("WORD", "0x%04lx")
43 DWORD = Intrinsic("DWORD", "0x%08lx")
45 BOOL = Intrinsic("BOOL", "%i")
47 LPLONG = Pointer(LONG)
48 LPWORD = Pointer(WORD)
49 LPDWORD = Pointer(DWORD)
50 LPBOOL = Pointer(BOOL)
54 LPCSTR = Const(String)
56 LPCWSTR = Const(WString)
58 LARGE_INTEGER = Intrinsic("LARGE_INTEGER", "0x%llx")
59 SIZE_T = Alias("SIZE_T", SizeT)
61 HRESULT = Alias("HRESULT", Int)
63 PVOID = Intrinsic("PVOID", "%p")
65 HANDLE = Intrinsic("HANDLE", "%p")
66 HWND = Intrinsic("HWND", "%p")
67 HDC = Intrinsic("HDC", "%p")
68 HMONITOR = Intrinsic("HMONITOR", "%p")
70 GUID = Struct("GUID", [
83 LPGUID = Pointer(GUID)
85 #REFGUID = Alias("REFGUID", Pointer(GUID))
86 REFGUID = Alias("REFGUID", GUID)
88 IID = Alias("IID", GUID)
89 #REFIID = Alias("REFIID", Pointer(IID))
90 REFIID = Alias("REFIID", IID)
92 CLSID = Alias("CLSID", GUID)
93 #REFCLSID = Alias("REFCLSID", Pointer(CLSID))
94 REFCLSID = Alias("REFCLSID", CLSID)
96 LUID = Struct("LUID", [
101 POINT = Struct("POINT", (
105 LPPOINT = Pointer(POINT)
107 RECT = Struct("RECT", (
113 LPRECT = Pointer(RECT)
115 PALETTEENTRY = Struct("PALETTEENTRY", (
121 LPPALETTEENTRY = Pointer(PALETTEENTRY)
124 RGNDATAHEADER = Struct("RGNDATAHEADER", [
132 RGNDATA = Struct("RGNDATA", [
133 (RGNDATAHEADER, "rdh"),
134 #(Char, "Buffer[1]"),
136 LPRGNDATA = Pointer(RGNDATA)
138 HMODULE = Alias("HMODULE", LPVOID)
140 IUnknown = Interface("IUnknown")
143 Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(Pointer(Void)), "ppvObj"))),
144 Method(ULONG, "AddRef", ()),
145 Method(ULONG, "Release", ()),
149 class DllFunction(Function):
151 def get_true_pointer(self):
152 ptype = self.pointer_type()
153 pvalue = self.pointer_value()
154 print ' if(!g_hDll) {'
155 print ' g_hDll = LoadLibrary(g_szDll);'
159 print ' if(!%s) {' % (pvalue,)
160 print ' %s = (%s)GetProcAddress(g_hDll, "%s");' % (pvalue, ptype, self.name)
161 print ' if(!%s)' % (pvalue,)
168 def __init__(self, name):
171 if self not in towrap:
175 return "Wrap" + self.name
177 def wrap_pre_decl(self):
181 print 'static HINSTANCE g_hDll = NULL;'
182 print 'static TCHAR g_szDll[MAX_PATH] = {0};'
184 print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);'
186 for function in self.functions:
191 print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
192 print r' switch(fdwReason) {'
193 print r' case DLL_PROCESS_ATTACH:'
194 print r' if(!GetSystemDirectory(g_szDll, MAX_PATH))'
195 print r' return FALSE;'
196 print r' _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
197 print r' Log::Open("%s");' % self.name
198 print r' case DLL_THREAD_ATTACH:'
199 print r' return TRUE;'
200 print r' case DLL_THREAD_DETACH:'
201 print r' return TRUE;'
202 print r' case DLL_PROCESS_DETACH:'
203 print r' Log::Close();'
204 print r' if(g_hDll) {'
205 print r' FreeLibrary(g_hDll);'
206 print r' g_hDll = NULL;'
208 print r' return TRUE;'
210 print r' (void)hinstDLL;'
211 print r' (void)lpvReserved;'
212 print r' return TRUE;'
215 for function in self.functions: