blob: 4202f06781648d39ee7616e769e4005e43d37520 [file] [log] [blame]
José Fonseca95442442008-07-08 10:32:53 +09001#############################################################################
2#
José Fonsecaf6c86992008-07-10 22:44:57 +09003# Copyright 2008 Tungsten Graphics, Inc.
José Fonseca95442442008-07-08 10:32:53 +09004#
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.
9#
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.
14#
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/>.
17#
18#############################################################################
19
José Fonsecad626cf42008-07-07 07:43:16 +090020"""windows.h"""
21
22from base import *
23
José Fonseca73f33cc2008-07-09 02:17:51 +090024SHORT = Intrinsic("SHORT", "%i")
25USHORT = Intrinsic("USHORT", "%u")
26INT = Intrinsic("INT", "%i")
José Fonsecad626cf42008-07-07 07:43:16 +090027UINT = Intrinsic("UINT", "%u")
28LONG = Intrinsic("LONG", "%li")
29ULONG = Intrinsic("ULONG", "%lu")
José Fonseca73f33cc2008-07-09 02:17:51 +090030FLOAT = Intrinsic("FLOAT", "%f")
31
32INT32 = Intrinsic("INT32", "%i")
33UINT32 = Intrinsic("UINT32", "%i")
José Fonsecad626cf42008-07-07 07:43:16 +090034
José Fonseca0dcc85c2008-07-08 07:34:54 +090035BYTE = Intrinsic("BYTE", "0x%02lx")
36WORD = Intrinsic("WORD", "0x%04lx")
37DWORD = Intrinsic("DWORD", "0x%08lx")
José Fonsecad626cf42008-07-07 07:43:16 +090038
39BOOL = Intrinsic("BOOL", "%i")
40
José Fonsecac569f872009-01-04 16:45:17 +000041LPLONG = Pointer(LONG)
42LPWORD = Pointer(WORD)
43LPDWORD = Pointer(DWORD)
44LPBOOL = Pointer(BOOL)
45LPSIZE = LPDWORD
46
47LPSTR = String
José Fonseca36e25aa2009-04-13 14:08:08 +010048LPCSTR = Const(String)
José Fonsecae54e4112009-06-25 13:56:18 +010049LPWSTR = WString
José Fonseca44eaac92009-06-30 19:48:50 +010050LPCWSTR = Const(WString)
José Fonsecac569f872009-01-04 16:45:17 +000051
José Fonseca4a9c40c2008-07-07 18:04:53 +090052LARGE_INTEGER = Intrinsic("LARGE_INTEGER", "0x%llx")
José Fonsecad626cf42008-07-07 07:43:16 +090053
54HRESULT = Alias("HRESULT", Int)
55
56PVOID = Intrinsic("PVOID", "%p")
José Fonsecac569f872009-01-04 16:45:17 +000057LPVOID = PVOID
José Fonseca73f33cc2008-07-09 02:17:51 +090058HANDLE = Intrinsic("HANDLE", "%p")
José Fonsecad626cf42008-07-07 07:43:16 +090059HWND = Intrinsic("HWND", "%p")
José Fonseca73f33cc2008-07-09 02:17:51 +090060HDC = Intrinsic("HDC", "%p")
José Fonsecad626cf42008-07-07 07:43:16 +090061HMONITOR = Intrinsic("HMONITOR", "%p")
62
José Fonseca8a56d142008-07-09 12:18:08 +090063GUID = Struct("GUID", [
64 (DWORD, "Data1"),
65 (WORD, "Data2"),
66 (WORD, "Data3"),
67 (BYTE, "Data4[0]"),
68 (BYTE, "Data4[1]"),
69 (BYTE, "Data4[2]"),
70 (BYTE, "Data4[3]"),
71 (BYTE, "Data4[4]"),
72 (BYTE, "Data4[5]"),
73 (BYTE, "Data4[6]"),
74 (BYTE, "Data4[7]"),
75])
José Fonsecac569f872009-01-04 16:45:17 +000076LPGUID = Pointer(GUID)
José Fonseca8a56d142008-07-09 12:18:08 +090077
78#REFGUID = Alias("REFGUID", Pointer(GUID))
79REFGUID = Alias("REFGUID", GUID)
80
81IID = Alias("IID", GUID)
82#REFIID = Alias("REFIID", Pointer(IID))
83REFIID = Alias("REFIID", IID)
84
José Fonsecac569f872009-01-04 16:45:17 +000085CLSID = Alias("CLSID", GUID)
86#REFCLSID = Alias("REFCLSID", Pointer(CLSID))
87REFCLSID = Alias("REFCLSID", CLSID)
88
José Fonseca8a56d142008-07-09 12:18:08 +090089LUID = Struct("LUID", [
90 (DWORD, "LowPart"),
91 (LONG, "HighPart"),
92])
José Fonsecad626cf42008-07-07 07:43:16 +090093
94POINT = Struct("POINT", (
95 (LONG, "x"),
96 (LONG, "y"),
97))
José Fonsecac569f872009-01-04 16:45:17 +000098LPPOINT = Pointer(POINT)
José Fonsecad626cf42008-07-07 07:43:16 +090099
100RECT = Struct("RECT", (
101 (LONG, "left"),
102 (LONG, "top"),
103 (LONG, "right"),
104 (LONG, "bottom"),
105))
José Fonsecac569f872009-01-04 16:45:17 +0000106LPRECT = Pointer(RECT)
José Fonsecad626cf42008-07-07 07:43:16 +0900107
108PALETTEENTRY = Struct("PALETTEENTRY", (
109 (BYTE, "peRed"),
110 (BYTE, "peGreen"),
111 (BYTE, "peBlue"),
112 (BYTE, "peFlags"),
113))
José Fonsecac569f872009-01-04 16:45:17 +0000114LPPALETTEENTRY = Pointer(PALETTEENTRY)
José Fonsecad626cf42008-07-07 07:43:16 +0900115
José Fonseca8a56d142008-07-09 12:18:08 +0900116
117RGNDATAHEADER = Struct("RGNDATAHEADER", [
118 (DWORD, "dwSize"),
119 (DWORD, "iType"),
120 (DWORD, "nCount"),
121 (DWORD, "nRgnSize"),
122 (RECT, "rcBound"),
123])
124
125RGNDATA = Struct("RGNDATA", [
126 (RGNDATAHEADER, "rdh"),
127 #(Char, "Buffer[1]"),
128])
José Fonsecac569f872009-01-04 16:45:17 +0000129LPRGNDATA = Pointer(RGNDATA)
José Fonsecad626cf42008-07-07 07:43:16 +0900130
131
132IUnknown = Interface("IUnknown")
133
134IUnknown.methods = (
135 Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(Pointer(Void)), "ppvObj"))),
136 Method(ULONG, "AddRef", ()),
137 Method(ULONG, "Release", ()),
138)
139
140
José Fonseca3c2c9292009-05-04 12:16:30 +0100141class DllFunction(Function):
142
143 def get_true_pointer(self):
144 ptype = self.pointer_type()
145 pvalue = self.pointer_value()
146 print ' if(!g_hDll) {'
147 print ' g_hDll = LoadLibrary(g_szDll);'
148 print ' if(!g_hDll)'
149 self.fail_impl()
150 print ' }'
151 print ' if(!%s) {' % (pvalue,)
José Fonsecac77023d2009-05-04 12:53:50 +0100152 print ' %s = (%s)GetProcAddress(g_hDll, "%s");' % (pvalue, ptype, self.name)
José Fonseca3c2c9292009-05-04 12:16:30 +0100153 print ' if(!%s)' % (pvalue,)
154 self.fail_impl()
155 print ' }'
156
157
José Fonsecad626cf42008-07-07 07:43:16 +0900158class Dll:
159
160 def __init__(self, name):
161 self.name = name
162 self.functions = []
163 if self not in towrap:
164 towrap.append(self)
165
166 def wrap_name(self):
167 return "Wrap" + self.name
168
169 def wrap_pre_decl(self):
170 pass
171
172 def wrap_decl(self):
José Fonsecad626cf42008-07-07 07:43:16 +0900173 print 'static HINSTANCE g_hDll = NULL;'
José Fonsecad7605892008-07-07 13:09:31 +0900174 print 'static TCHAR g_szDll[MAX_PATH] = {0};'
José Fonsecad626cf42008-07-07 07:43:16 +0900175 print
176 print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);'
177 print
José Fonseca3c2c9292009-05-04 12:16:30 +0100178 for function in self.functions:
179 function.wrap_decl()
180 print
José Fonsecad626cf42008-07-07 07:43:16 +0900181
182 def wrap_impl(self):
183 print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
José Fonsecad626cf42008-07-07 07:43:16 +0900184 print r' switch(fdwReason) {'
185 print r' case DLL_PROCESS_ATTACH:'
José Fonsecad7605892008-07-07 13:09:31 +0900186 print r' if(!GetSystemDirectory(g_szDll, MAX_PATH))'
José Fonsecad626cf42008-07-07 07:43:16 +0900187 print r' return FALSE;'
José Fonsecad7605892008-07-07 13:09:31 +0900188 print r' _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
José Fonsecadf824982009-04-13 13:49:51 +0100189 print r' Log::Open("%s");' % self.name
José Fonsecad626cf42008-07-07 07:43:16 +0900190 print r' case DLL_THREAD_ATTACH:'
191 print r' return TRUE;'
192 print r' case DLL_THREAD_DETACH:'
José Fonsecad7605892008-07-07 13:09:31 +0900193 print r' return TRUE;'
194 print r' case DLL_PROCESS_DETACH:'
José Fonseca22aec832008-07-09 09:38:45 +0900195 print r' Log::Close();'
José Fonsecad7605892008-07-07 13:09:31 +0900196 print r' if(g_hDll) {'
197 print r' FreeLibrary(g_hDll);'
198 print r' g_hDll = NULL;'
199 print r' }'
José Fonsecad626cf42008-07-07 07:43:16 +0900200 print r' return TRUE;'
201 print r' }'
José Fonsecad7605892008-07-07 13:09:31 +0900202 print r' (void)hinstDLL;'
José Fonsecad626cf42008-07-07 07:43:16 +0900203 print r' (void)lpvReserved;'
204 print r' return TRUE;'
205 print r'}'
206 print
207 for function in self.functions:
José Fonseca3c2c9292009-05-04 12:16:30 +0100208 function.wrap_impl()
José Fonsecad626cf42008-07-07 07:43:16 +0900209 print
210