From c77023dffd220878d4d0c47fd084721a95284f8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 4 May 2009 12:53:50 +0100 Subject: [PATCH] Basic support to trace functions obtained via wglGetProcAddress. --- base.py | 4 ++++ opengl32.py | 43 ++++++++++++++++++++++++++++++++++++++++++- windows.py | 2 +- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/base.py b/base.py index a901aeb..0dbec4c 100644 --- a/base.py +++ b/base.py @@ -323,11 +323,15 @@ class Function: print ' Log::EndReturn();' self.type.wrap_instance('result') print ' Log::EndCall();' + self.post_call_impl() if self.type is not Void: print ' return result;' print '}' print + def post_call_impl(self): + pass + class Interface(Type): diff --git a/opengl32.py b/opengl32.py index 539d466..e12ec87 100644 --- a/opengl32.py +++ b/opengl32.py @@ -533,7 +533,6 @@ opengl32.functions += [ DllFunction(BOOL, "wglDeleteContext", [(HGLRC, "hglrc")]), DllFunction(HGLRC, "wglGetCurrentContext", []), DllFunction(HDC, "wglGetCurrentDC", []), - DllFunction(PROC, "wglGetProcAddress", [(LPCSTR, "lpszProc")]), DllFunction(PROC, "wglGetDefaultProcAddress", [(LPCSTR, "lpszProc")]), DllFunction(Int, "wglChoosePixelFormat", [(HDC, "hdc"), (Pointer(Const(PIXELFORMATDESCRIPTOR)), "ppfd")]), DllFunction(Int, "wglDescribePixelFormat", [(HDC, "hdc"), (Int, "iPixelFormat"), (UINT, "nBytes"), (OutPointer(PIXELFORMATDESCRIPTOR), "ppfd")]), @@ -563,6 +562,48 @@ if False: DllFunction(DWORD, "wglSwapMultipleBuffers", [(UINT, "n"), (Pointer(Const(WGLSWAP)), "ps")]), ] + +class WglGetProcAddressFunction(DllFunction): + + def __init__(self, type, name, args): + DllFunction.__init__(self, type, name, args) + self.functions = [] + + def wrap_decl(self): + for function in self.functions: + function.wrap_decl() + DllFunction.wrap_decl(self) + + def wrap_impl(self): + for function in self.functions: + function.wrap_impl() + DllFunction.wrap_impl(self) + + def post_call_impl(self): + for function in self.functions: + ptype = function.pointer_type() + pvalue = function.pointer_value() + print ' if(!strcmp("%s", lpszProc)) {' % function.name + print ' %s = (%s)result;' % (pvalue, ptype) + print ' result = (PROC)&%s;' % function.name; + print ' }' + + +wglgetprocaddress = WglGetProcAddressFunction(PROC, "wglGetProcAddress", [(LPCSTR, "lpszProc")]) +opengl32.functions.append(wglgetprocaddress) + +class WglFunction(Function): + + def get_true_pointer(self): + ptype = self.pointer_type() + pvalue = self.pointer_value() + print ' if(!%s)' % (pvalue,) + self.fail_impl() + +wglgetprocaddress.functions += [ + WglFunction(Const(String), "wglGetExtensionsStringARB", [(HDC, "hdc")]), +] + if __name__ == '__main__': print print '#define _GDI32_' diff --git a/windows.py b/windows.py index 4db8616..59d6591 100644 --- a/windows.py +++ b/windows.py @@ -148,7 +148,7 @@ class DllFunction(Function): self.fail_impl() print ' }' print ' if(!%s) {' % (pvalue,) - print ' %s = (%s)GetProcAddress( g_hDll, "%s");' % (pvalue, ptype, self.name) + print ' %s = (%s)GetProcAddress(g_hDll, "%s");' % (pvalue, ptype, self.name) print ' if(!%s)' % (pvalue,) self.fail_impl() print ' }' -- 2.7.4