]> git.cworth.org Git - apitrace/blob - windows.py
Rudimentary support for D3D10.
[apitrace] / windows.py
1 #############################################################################
2 #
3 # Copyright 2008 Tungsten Graphics, Inc.
4 #
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
20 """windows.h"""
21
22 from base import *
23
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")
31
32 INT32 = Intrinsic("INT32", "%i")
33 UINT32 = Intrinsic("UINT32", "%i")
34
35 BYTE = Intrinsic("BYTE", "0x%02lx")
36 WORD = Intrinsic("WORD", "0x%04lx")
37 DWORD = Intrinsic("DWORD", "0x%08lx")
38
39 BOOL = Intrinsic("BOOL", "%i")
40
41 LPLONG = Pointer(LONG)
42 LPWORD = Pointer(WORD)
43 LPDWORD = Pointer(DWORD)
44 LPBOOL = Pointer(BOOL)
45 LPSIZE = LPDWORD
46
47 LPSTR = String
48 LPCSTR = Const(String)
49 LPWSTR = WString
50 LPCWSTR = Const(WString)
51
52 LARGE_INTEGER = Intrinsic("LARGE_INTEGER", "0x%llx")
53 SIZE_T = Alias("SIZE_T", SizeT)
54
55 HRESULT = Alias("HRESULT", Int)
56
57 PVOID = Intrinsic("PVOID", "%p")
58 LPVOID = PVOID
59 HANDLE = Intrinsic("HANDLE", "%p")
60 HWND = Intrinsic("HWND", "%p")
61 HDC = Intrinsic("HDC", "%p")
62 HMONITOR = Intrinsic("HMONITOR", "%p")
63
64 GUID = Struct("GUID", [
65     (DWORD, "Data1"),
66     (WORD, "Data2"),
67     (WORD, "Data3"),
68     (BYTE, "Data4[0]"),
69     (BYTE, "Data4[1]"),
70     (BYTE, "Data4[2]"),
71     (BYTE, "Data4[3]"),
72     (BYTE, "Data4[4]"),
73     (BYTE, "Data4[5]"),
74     (BYTE, "Data4[6]"),
75     (BYTE, "Data4[7]"),
76 ])
77 LPGUID = Pointer(GUID)
78
79 #REFGUID = Alias("REFGUID", Pointer(GUID))
80 REFGUID = Alias("REFGUID", GUID)
81
82 IID = Alias("IID", GUID)
83 #REFIID = Alias("REFIID", Pointer(IID))
84 REFIID = Alias("REFIID", IID)
85
86 CLSID = Alias("CLSID", GUID)
87 #REFCLSID = Alias("REFCLSID", Pointer(CLSID))
88 REFCLSID = Alias("REFCLSID", CLSID)
89
90 LUID = Struct("LUID", [
91     (DWORD, "LowPart"),
92     (LONG, "HighPart"),
93 ])
94
95 POINT = Struct("POINT", (
96   (LONG, "x"),
97   (LONG, "y"),
98 )) 
99 LPPOINT = Pointer(POINT)
100
101 RECT = Struct("RECT", (
102   (LONG, "left"),
103   (LONG, "top"),
104   (LONG, "right"), 
105   (LONG, "bottom"), 
106 )) 
107 LPRECT = Pointer(RECT)
108
109 PALETTEENTRY = Struct("PALETTEENTRY", (
110   (BYTE, "peRed"),
111   (BYTE, "peGreen"),
112   (BYTE, "peBlue"), 
113   (BYTE, "peFlags"), 
114 )) 
115 LPPALETTEENTRY = Pointer(PALETTEENTRY)
116
117
118 RGNDATAHEADER = Struct("RGNDATAHEADER", [
119     (DWORD, "dwSize"),
120     (DWORD, "iType"),
121     (DWORD, "nCount"),
122     (DWORD, "nRgnSize"),
123     (RECT, "rcBound"),
124 ])
125
126 RGNDATA = Struct("RGNDATA", [
127     (RGNDATAHEADER, "rdh"),
128     #(Char, "Buffer[1]"),
129 ])
130 LPRGNDATA = Pointer(RGNDATA)
131
132 HMODULE = Alias("HMODULE", LPVOID)
133
134 IUnknown = Interface("IUnknown")
135
136 IUnknown.methods = (
137         Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(Pointer(Void)), "ppvObj"))),
138         Method(ULONG, "AddRef", ()),
139         Method(ULONG, "Release", ()),
140 )
141
142
143 class DllFunction(Function):
144
145     def get_true_pointer(self):
146         ptype = self.pointer_type()
147         pvalue = self.pointer_value()
148         print '    if(!g_hDll) {'
149         print '        g_hDll = LoadLibrary(g_szDll);'
150         print '        if(!g_hDll)'
151         self.fail_impl()
152         print '    }'
153         print '    if(!%s) {' % (pvalue,)
154         print '        %s = (%s)GetProcAddress(g_hDll, "%s");' % (pvalue, ptype, self.name)
155         print '        if(!%s)' % (pvalue,)
156         self.fail_impl()
157         print '    }'
158
159
160 class Dll:
161
162     def __init__(self, name):
163         self.name = name
164         self.functions = []
165         if self not in towrap:
166             towrap.append(self)
167
168     def wrap_name(self):
169         return "Wrap" + self.name
170
171     def wrap_pre_decl(self):
172         pass
173
174     def wrap_decl(self):
175         print 'static HINSTANCE g_hDll = NULL;'
176         print 'static TCHAR g_szDll[MAX_PATH] = {0};'
177         print
178         print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);'
179         print
180         for function in self.functions:
181             function.wrap_decl()
182         print
183
184     def wrap_impl(self):
185         print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
186         print r'    switch(fdwReason) {'
187         print r'    case DLL_PROCESS_ATTACH:'
188         print r'        if(!GetSystemDirectory(g_szDll, MAX_PATH))'
189         print r'            return FALSE;'
190         print r'        _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
191         print r'        Log::Open("%s");' % self.name
192         print r'    case DLL_THREAD_ATTACH:'
193         print r'        return TRUE;'
194         print r'    case DLL_THREAD_DETACH:'
195         print r'        return TRUE;'
196         print r'    case DLL_PROCESS_DETACH:'
197         print r'        Log::Close();'
198         print r'        if(g_hDll) {'
199         print r'            FreeLibrary(g_hDll);'
200         print r'            g_hDll = NULL;'
201         print r'        }'
202         print r'        return TRUE;'
203         print r'    }'
204         print r'    (void)hinstDLL;'
205         print r'    (void)lpvReserved;'
206         print r'    return TRUE;'
207         print r'}'
208         print
209         for function in self.functions:
210             function.wrap_impl()
211         print
212