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)
48 LPCSTR = Const(String)
51 LARGE_INTEGER = Intrinsic("LARGE_INTEGER", "0x%llx")
53 HRESULT = Alias("HRESULT", Int)
55 PVOID = Intrinsic("PVOID", "%p")
57 HANDLE = Intrinsic("HANDLE", "%p")
58 HWND = Intrinsic("HWND", "%p")
59 HDC = Intrinsic("HDC", "%p")
60 HMONITOR = Intrinsic("HMONITOR", "%p")
62 GUID = Struct("GUID", [
75 LPGUID = Pointer(GUID)
77 #REFGUID = Alias("REFGUID", Pointer(GUID))
78 REFGUID = Alias("REFGUID", GUID)
80 IID = Alias("IID", GUID)
81 #REFIID = Alias("REFIID", Pointer(IID))
82 REFIID = Alias("REFIID", IID)
84 CLSID = Alias("CLSID", GUID)
85 #REFCLSID = Alias("REFCLSID", Pointer(CLSID))
86 REFCLSID = Alias("REFCLSID", CLSID)
88 LUID = Struct("LUID", [
93 POINT = Struct("POINT", (
97 LPPOINT = Pointer(POINT)
99 RECT = Struct("RECT", (
105 LPRECT = Pointer(RECT)
107 PALETTEENTRY = Struct("PALETTEENTRY", (
113 LPPALETTEENTRY = Pointer(PALETTEENTRY)
116 RGNDATAHEADER = Struct("RGNDATAHEADER", [
124 RGNDATA = Struct("RGNDATA", [
125 (RGNDATAHEADER, "rdh"),
126 #(Char, "Buffer[1]"),
128 LPRGNDATA = Pointer(RGNDATA)
131 IUnknown = Interface("IUnknown")
134 Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(Pointer(Void)), "ppvObj"))),
135 Method(ULONG, "AddRef", ()),
136 Method(ULONG, "Release", ()),
140 class DllFunction(Function):
142 def get_true_pointer(self):
143 ptype = self.pointer_type()
144 pvalue = self.pointer_value()
145 print ' if(!g_hDll) {'
146 print ' g_hDll = LoadLibrary(g_szDll);'
150 print ' if(!%s) {' % (pvalue,)
151 print ' %s = (%s)GetProcAddress( g_hDll, "%s");' % (pvalue, ptype, self.name)
152 print ' if(!%s)' % (pvalue,)
159 def __init__(self, name):
162 if self not in towrap:
166 return "Wrap" + self.name
168 def wrap_pre_decl(self):
172 print 'static HINSTANCE g_hDll = NULL;'
173 print 'static TCHAR g_szDll[MAX_PATH] = {0};'
175 print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);'
177 for function in self.functions:
182 print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
183 print r' switch(fdwReason) {'
184 print r' case DLL_PROCESS_ATTACH:'
185 print r' if(!GetSystemDirectory(g_szDll, MAX_PATH))'
186 print r' return FALSE;'
187 print r' _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
188 print r' Log::Open("%s");' % self.name
189 print r' case DLL_THREAD_ATTACH:'
190 print r' return TRUE;'
191 print r' case DLL_THREAD_DETACH:'
192 print r' return TRUE;'
193 print r' case DLL_PROCESS_DETACH:'
194 print r' Log::Close();'
195 print r' if(g_hDll) {'
196 print r' FreeLibrary(g_hDll);'
197 print r' g_hDll = NULL;'
199 print r' return TRUE;'
201 print r' (void)hinstDLL;'
202 print r' (void)lpvReserved;'
203 print r' return TRUE;'
206 for function in self.functions: