From 290c28c2ad1b0cc7de830f9a665e8b2368e0def0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 23 Apr 2009 15:20:29 +0100 Subject: [PATCH] Try to cope with missing functions. In particular Direct3DCreate9Ex is only defined on Vista. --- base.py | 3 ++- d3d9.py | 4 ++-- windows.py | 6 +++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/base.py b/base.py index 1632bc0..2678ab8 100644 --- a/base.py +++ b/base.py @@ -224,11 +224,12 @@ class Alias(Type): class Function: - def __init__(self, type, name, args, call = '__stdcall'): + def __init__(self, type, name, args, call = '__stdcall', fail = None): self.type = type self.name = name self.args = args self.call = call + self.fail = fail def prototype(self, name=None): if name is not None: diff --git a/d3d9.py b/d3d9.py index 6e4ce24..152d485 100644 --- a/d3d9.py +++ b/d3d9.py @@ -383,8 +383,8 @@ IDirect3DSwapChain9Ex.methods += [ d3d9 = Dll("d3d9") d3d9.functions += [ - Function(PDIRECT3D9, "Direct3DCreate9", [(UINT, "SDKVersion")]), - Function(HRESULT, "Direct3DCreate9Ex", [(UINT, "SDKVersion"), (OutPointer(PDIRECT3D9EX), "ppD3D")]), + Function(PDIRECT3D9, "Direct3DCreate9", [(UINT, "SDKVersion")], fail='NULL'), + Function(HRESULT, "Direct3DCreate9Ex", [(UINT, "SDKVersion"), (OutPointer(PDIRECT3D9EX), "ppD3D")], fail='D3DERR_NOTAVAILABLE'), ] if __name__ == '__main__': diff --git a/windows.py b/windows.py index ba6ca5a..a149e6a 100644 --- a/windows.py +++ b/windows.py @@ -204,7 +204,11 @@ class Dll: print ' }' print ' pFunction = (%s)GetProcAddress( g_hDll, "%s");' % (type, function.name) print ' if(!pFunction)' - print ' ExitProcess(0);' + if function.fail is not None: + assert function.type is not Void + print ' return %s;' % function.fail + else: + print ' ExitProcess(0);' print ' Log::BeginCall("%s");' % (function.name) for type, name in function.args: if not type.isoutput(): -- 2.45.2