1 #############################################################################
3 # Copyright 2008 Tungsten Graphics, Inc.
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published
7 # by the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #############################################################################
24 SHORT = Intrinsic("SHORT", "%i")
25 USHORT = Intrinsic("USHORT", "%u")
26 INT = Intrinsic("INT", "%i")
27 UINT = Intrinsic("UINT", "%u")
28 LONG = Intrinsic("LONG", "%li")
29 ULONG = Intrinsic("ULONG", "%lu")
30 FLOAT = Intrinsic("FLOAT", "%f")
32 INT32 = Intrinsic("INT32", "%i")
33 UINT32 = Intrinsic("UINT32", "%i")
35 BYTE = Intrinsic("BYTE", "0x%02lx")
36 WORD = Intrinsic("WORD", "0x%04lx")
37 DWORD = Intrinsic("DWORD", "0x%08lx")
39 BOOL = Intrinsic("BOOL", "%i")
41 LPLONG = Pointer(LONG)
42 LPWORD = Pointer(WORD)
43 LPDWORD = Pointer(DWORD)
44 LPBOOL = Pointer(BOOL)
50 LARGE_INTEGER = Intrinsic("LARGE_INTEGER", "0x%llx")
52 HRESULT = Alias("HRESULT", Int)
54 PVOID = Intrinsic("PVOID", "%p")
56 HANDLE = Intrinsic("HANDLE", "%p")
57 HWND = Intrinsic("HWND", "%p")
58 HDC = Intrinsic("HDC", "%p")
59 HMONITOR = Intrinsic("HMONITOR", "%p")
61 GUID = Struct("GUID", [
74 LPGUID = Pointer(GUID)
76 #REFGUID = Alias("REFGUID", Pointer(GUID))
77 REFGUID = Alias("REFGUID", GUID)
79 IID = Alias("IID", GUID)
80 #REFIID = Alias("REFIID", Pointer(IID))
81 REFIID = Alias("REFIID", IID)
83 CLSID = Alias("CLSID", GUID)
84 #REFCLSID = Alias("REFCLSID", Pointer(CLSID))
85 REFCLSID = Alias("REFCLSID", CLSID)
87 LUID = Struct("LUID", [
92 POINT = Struct("POINT", (
96 LPPOINT = Pointer(POINT)
98 RECT = Struct("RECT", (
104 LPRECT = Pointer(RECT)
106 PALETTEENTRY = Struct("PALETTEENTRY", (
112 LPPALETTEENTRY = Pointer(PALETTEENTRY)
115 RGNDATAHEADER = Struct("RGNDATAHEADER", [
123 RGNDATA = Struct("RGNDATA", [
124 (RGNDATAHEADER, "rdh"),
125 #(Char, "Buffer[1]"),
127 LPRGNDATA = Pointer(RGNDATA)
130 IUnknown = Interface("IUnknown")
133 Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(Pointer(Void)), "ppvObj"))),
134 Method(ULONG, "AddRef", ()),
135 Method(ULONG, "Release", ()),
141 def __init__(self, name):
144 if self not in towrap:
148 return "Wrap" + self.name
150 def wrap_pre_decl(self):
154 print 'static HINSTANCE g_hDll = NULL;'
155 print 'static TCHAR g_szDll[MAX_PATH] = {0};'
157 print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);'
161 print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
162 print r' switch(fdwReason) {'
163 print r' case DLL_PROCESS_ATTACH:'
164 print r' if(!GetSystemDirectory(g_szDll, MAX_PATH))'
165 print r' return FALSE;'
166 print r' _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
167 print r' Log::Open("%s");' % self.name
168 print r' case DLL_THREAD_ATTACH:'
169 print r' return TRUE;'
170 print r' case DLL_THREAD_DETACH:'
171 print r' return TRUE;'
172 print r' case DLL_PROCESS_DETACH:'
173 print r' Log::Close();'
174 print r' if(g_hDll) {'
175 print r' FreeLibrary(g_hDll);'
176 print r' g_hDll = NULL;'
178 print r' return TRUE;'
180 print r' (void)hinstDLL;'
181 print r' (void)lpvReserved;'
182 print r' return TRUE;'
185 for function in self.functions:
186 type = 'P' + function.name
187 print function.prototype() + ' {'
189 print ' Log::Close();'
190 print ' Log::Open("%s");' % self.name
191 #print ' Log::ReOpen();'
192 print ' typedef ' + function.prototype('* %s' % type) + ';'
193 print ' %s pFunction;' % type
194 if function.type is Void:
197 print ' %s result;' % function.type
199 print ' if(!g_hDll) {'
200 print ' g_hDll = LoadLibrary(g_szDll);'
202 print ' ExitProcess(0);'
204 print ' pFunction = (%s)GetProcAddress( g_hDll, "%s");' % (type, function.name)
205 print ' if(!pFunction)'
206 print ' ExitProcess(0);'
207 print ' Log::BeginCall("%s");' % (function.name)
208 for type, name in function.args:
209 if not type.isoutput():
210 type.unwrap_instance(name)
211 print ' Log::BeginArg("%s", "%s");' % (type, name)
213 print ' Log::EndArg();'
214 print ' %spFunction(%s);' % (result, ', '.join([str(name) for type, name in function.args]))
215 for type, name in function.args:
217 print ' Log::BeginArg("%s", "%s");' % (type, name)
219 print ' Log::EndArg();'
220 type.wrap_instance(name)
221 if function.type is not Void:
222 print ' Log::BeginReturn("%s");' % function.type
223 function.type.dump("result")
224 print ' Log::EndReturn();'
225 function.type.wrap_instance('result')
226 print ' Log::EndCall();'
227 if function.type is not Void:
228 print ' return result;'