From: José Fonseca Date: Thu, 25 Nov 2010 11:39:57 +0000 (+0000) Subject: windows.py -> winapi.py X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=f20c12630e0f1e12c4740478ab760b0013592946;p=apitrace windows.py -> winapi.py --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 30befd3..99dde68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ if (WIN32) # add_custom_command ( # OUTPUT d3d8.cpp # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp - # DEPENDS d3d8.py d3d8types.py d3d8caps.py windows.py base.py + # DEPENDS d3d8.py d3d8types.py d3d8caps.py winapi.py base.py # ) # add_library (d3d8 SHARED d3d8.def d3d8.cpp log.cpp os_win32.cpp) # set_target_properties (d3d8 PROPERTIES PREFIX "") @@ -107,7 +107,7 @@ if (WIN32) # add_custom_command ( # OUTPUT d3d9.cpp # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp - # DEPENDS d3d9.py d3d9types.py d3d9caps.py d3dshader.py windows.py base.py + # DEPENDS d3d9.py d3d9types.py d3d9caps.py d3dshader.py winapi.py base.py # ) # add_library (d3d9 SHARED d3d9.def d3d9.cpp log.cpp os_win32.cpp) # set_target_properties (d3d9 PROPERTIES PREFIX "") @@ -119,7 +119,7 @@ if (WIN32) # add_custom_command ( # OUTPUT d3d10.cpp # COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp - # DEPENDS d3d10misc.py windows.py base.py + # DEPENDS d3d10misc.py winapi.py base.py # ) # add_library (d3d10 SHARED d3d10.def d3d10.cpp log.cpp os_win32.cpp) # set_target_properties (d3d10 PROPERTIES PREFIX "") @@ -129,7 +129,7 @@ if (WIN32) add_custom_command ( OUTPUT opengl32.cpp COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp - DEPENDS opengl32.py trace.py wglapi.py glapi.py windows.py base.py + DEPENDS opengl32.py trace.py wglapi.py glapi.py winapi.py base.py ) add_library (opengl SHARED opengl32.def opengl32.cpp log.cpp os_win32.cpp) set_target_properties (opengl PROPERTIES diff --git a/d3d.py b/d3d.py index 7b71158..f5b7638 100644 --- a/d3d.py +++ b/d3d.py @@ -25,7 +25,7 @@ """d3d.h""" -from windows import * +from winapi import * from d3dtypes import * from d3dcaps import * diff --git a/d3d10_1.py b/d3d10_1.py index b9fa9f9..14420da 100644 --- a/d3d10_1.py +++ b/d3d10_1.py @@ -25,7 +25,7 @@ """d3d10_1.h""" -from windows import * +from winapi import * ID3D10Blob = Interface("ID3D10Blob", IUnknown) LPD3D10BLOB = Pointer(ID3D10Blob) diff --git a/d3d10misc.py b/d3d10misc.py index 9e81b51..9396a56 100644 --- a/d3d10misc.py +++ b/d3d10misc.py @@ -25,7 +25,7 @@ """d3d10misc.h""" -from windows import * +from winapi import * ID3D10Blob = Interface("ID3D10Blob", IUnknown) LPD3D10BLOB = Pointer(ID3D10Blob) diff --git a/d3d8.py b/d3d8.py index a4f1f34..7204554 100644 --- a/d3d8.py +++ b/d3d8.py @@ -25,7 +25,7 @@ """d3d8.h""" -from windows import * +from winapi import * from d3d8types import * from d3d8caps import * diff --git a/d3d8caps.py b/d3d8caps.py index 36a332e..87e7625 100644 --- a/d3d8caps.py +++ b/d3d8caps.py @@ -25,7 +25,7 @@ """d3d8caps.h""" -from windows import * +from winapi import * from d3d8types import * D3DCAPS = Flags(DWORD, [ diff --git a/d3d8types.py b/d3d8types.py index 9f87b82..96e3d84 100644 --- a/d3d8types.py +++ b/d3d8types.py @@ -25,7 +25,7 @@ """d3d8types.h""" -from windows import * +from winapi import * D3DCOLOR = Alias("D3DCOLOR", DWORD) diff --git a/d3d9.py b/d3d9.py index 55f3dcd..4e1da90 100644 --- a/d3d9.py +++ b/d3d9.py @@ -25,7 +25,7 @@ """d3d9.h""" -from windows import * +from winapi import * from d3dshader import * from d3d9types import * from d3d9caps import * diff --git a/d3d9caps.py b/d3d9caps.py index 195052b..5140514 100644 --- a/d3d9caps.py +++ b/d3d9caps.py @@ -25,7 +25,7 @@ """d3d9caps.h""" -from windows import * +from winapi import * from d3d9types import * D3DVS20CAPS = Flags(DWORD, [ diff --git a/d3d9types.py b/d3d9types.py index cef8bd7..239f750 100644 --- a/d3d9types.py +++ b/d3d9types.py @@ -25,7 +25,7 @@ """d3d9types.h""" -from windows import * +from winapi import * D3DCOLOR = Alias("D3DCOLOR", DWORD) diff --git a/d3dcaps.py b/d3dcaps.py index 50ca351..6096826 100644 --- a/d3dcaps.py +++ b/d3dcaps.py @@ -25,7 +25,7 @@ """d3dcaps.h""" -from windows import * +from winapi import * from d3dtypes import * D3DTRANSFORMCAPS = Flags(DWORD, [ diff --git a/d3dtypes.py b/d3dtypes.py index 2f51783..07c70a3 100644 --- a/d3dtypes.py +++ b/d3dtypes.py @@ -25,7 +25,7 @@ """d3dtypes.h""" -from windows import * +from winapi import * from ddraw import * D3DVALUE = Float diff --git a/ddraw.py b/ddraw.py index d04ae90..bc1f8f2 100644 --- a/ddraw.py +++ b/ddraw.py @@ -25,7 +25,7 @@ """ddraw.h""" -from windows import * +from winapi import * IDirectDraw = Interface("IDirectDraw", IUnknown) IDirectDraw2 = Interface("IDirectDraw2", IUnknown) diff --git a/wglapi.py b/wglapi.py index 79128ac..e5611b2 100644 --- a/wglapi.py +++ b/wglapi.py @@ -25,7 +25,7 @@ from glapi import * -from windows import * +from winapi import * wglapi = API("WGL") diff --git a/winapi.py b/winapi.py new file mode 100644 index 0000000..eec3fde --- /dev/null +++ b/winapi.py @@ -0,0 +1,223 @@ +########################################################################## +# +# Copyright 2008-2009 VMware, Inc. +# All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +##########################################################################/ + +"""Win32 API type description.""" + +from base import * + +SHORT = Alias("SHORT", Short) +USHORT = Alias("USHORT", UShort) +INT = Alias("INT", Int) +UINT = Alias("UINT", UInt) +LONG = Alias("LONG", Long) +ULONG = Alias("ULONG", ULong) +LONGLONG = Alias("LONGLONG", LongLong) +FLOAT = Alias("FLOAT", Float) + +INT32 = Literal("INT32", "UInt") +UINT32 = Literal("UINT32", "UInt") + +BYTE = Literal("BYTE", "UInt", base=16) +WORD = Literal("WORD", "UInt", base=16) +DWORD = Literal("DWORD", "UInt", base=16) + +BOOL = Alias("BOOL", Bool) + +LPLONG = Pointer(LONG) +LPWORD = Pointer(WORD) +LPDWORD = Pointer(DWORD) +LPBOOL = Pointer(BOOL) +LPSIZE = LPDWORD + +LPSTR = CString +LPCSTR = Const(CString) +LPWSTR = WString +LPCWSTR = Const(WString) + +LARGE_INTEGER = Struct("LARGE_INTEGER", [ + (LONGLONG, 'QuadPart'), +]) + +SIZE_T = Alias("SIZE_T", SizeT) + +HRESULT = Alias("HRESULT", Int) + +VOID = Void +PVOID = Opaque("PVOID") +LPVOID = PVOID +HANDLE = Opaque("HANDLE") +HWND = Opaque("HWND") +HDC = Opaque("HDC") +HMONITOR = Opaque("HMONITOR") + +GUID = Struct("GUID", [ + (DWORD, "Data1"), + (WORD, "Data2"), + (WORD, "Data3"), + (BYTE, "Data4[0]"), + (BYTE, "Data4[1]"), + (BYTE, "Data4[2]"), + (BYTE, "Data4[3]"), + (BYTE, "Data4[4]"), + (BYTE, "Data4[5]"), + (BYTE, "Data4[6]"), + (BYTE, "Data4[7]"), +]) +LPGUID = Pointer(GUID) + +#REFGUID = Alias("REFGUID", Pointer(GUID)) +REFGUID = Alias("REFGUID", GUID) + +IID = Alias("IID", GUID) +#REFIID = Alias("REFIID", Pointer(IID)) +REFIID = Alias("REFIID", IID) + +CLSID = Alias("CLSID", GUID) +#REFCLSID = Alias("REFCLSID", Pointer(CLSID)) +REFCLSID = Alias("REFCLSID", CLSID) + +LUID = Struct("LUID", [ + (DWORD, "LowPart"), + (LONG, "HighPart"), +]) + +POINT = Struct("POINT", ( + (LONG, "x"), + (LONG, "y"), +)) +LPPOINT = Pointer(POINT) + +RECT = Struct("RECT", ( + (LONG, "left"), + (LONG, "top"), + (LONG, "right"), + (LONG, "bottom"), +)) +LPRECT = Pointer(RECT) + +PALETTEENTRY = Struct("PALETTEENTRY", ( + (BYTE, "peRed"), + (BYTE, "peGreen"), + (BYTE, "peBlue"), + (BYTE, "peFlags"), +)) +LPPALETTEENTRY = Pointer(PALETTEENTRY) + + +RGNDATAHEADER = Struct("RGNDATAHEADER", [ + (DWORD, "dwSize"), + (DWORD, "iType"), + (DWORD, "nCount"), + (DWORD, "nRgnSize"), + (RECT, "rcBound"), +]) + +RGNDATA = Struct("RGNDATA", [ + (RGNDATAHEADER, "rdh"), + #(Char, "Buffer[1]"), +]) +LPRGNDATA = Pointer(RGNDATA) + +HMODULE = Opaque("HMODULE") + +IUnknown = Interface("IUnknown") + +IUnknown.methods = ( + Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(OpaquePointer(Void)), "ppvObj"))), + Method(ULONG, "AddRef", ()), + Method(ULONG, "Release", ()), +) + + +class DllFunction(Function): + + def get_true_pointer(self): + ptype = self.pointer_type() + pvalue = self.pointer_value() + print ' if(!g_hDll) {' + print ' g_hDll = LoadLibrary(g_szDll);' + print ' if(!g_hDll)' + self.fail_impl() + print ' }' + print ' if(!%s) {' % (pvalue,) + print ' %s = (%s)GetProcAddress(g_hDll, "%s");' % (pvalue, ptype, self.name) + print ' if(!%s)' % (pvalue,) + self.fail_impl() + print ' }' + + +class Dll: + + def __init__(self, name): + self.name = name + self.functions = [] + if self not in towrap: + towrap.append(self) + + def wrap_name(self): + return "Wrap" + self.name + + def wrap_pre_decl(self): + pass + + def wrap_decl(self): + print 'static HINSTANCE g_hDll = NULL;' + print 'static TCHAR g_szDll[MAX_PATH] = {0};' + print + print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);' + print + for function in self.functions: + function.wrap_decl() + print + + def wrap_impl(self): + print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {' + print r' switch(fdwReason) {' + print r' case DLL_PROCESS_ATTACH:' + print r' if(!GetSystemDirectory(g_szDll, MAX_PATH))' + print r' return FALSE;' + print r' _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name + print r' Log::Open("%s");' % self.name + print r' case DLL_THREAD_ATTACH:' + print r' return TRUE;' + print r' case DLL_THREAD_DETACH:' + print r' return TRUE;' + print r' case DLL_PROCESS_DETACH:' + print r' Log::Close();' + print r' if(g_hDll) {' + print r' FreeLibrary(g_hDll);' + print r' g_hDll = NULL;' + print r' }' + print r' return TRUE;' + print r' }' + print r' (void)hinstDLL;' + print r' (void)lpvReserved;' + print r' return TRUE;' + print r'}' + print + for function in self.functions: + function.wrap_impl() + print + diff --git a/windows.py b/windows.py deleted file mode 100644 index 208961f..0000000 --- a/windows.py +++ /dev/null @@ -1,223 +0,0 @@ -########################################################################## -# -# Copyright 2008-2009 VMware, Inc. -# All Rights Reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -##########################################################################/ - -"""windows.h""" - -from base import * - -SHORT = Alias("SHORT", Short) -USHORT = Alias("USHORT", UShort) -INT = Alias("INT", Int) -UINT = Alias("UINT", UInt) -LONG = Alias("LONG", Long) -ULONG = Alias("ULONG", ULong) -LONGLONG = Alias("LONGLONG", LongLong) -FLOAT = Alias("FLOAT", Float) - -INT32 = Literal("INT32", "UInt") -UINT32 = Literal("UINT32", "UInt") - -BYTE = Literal("BYTE", "UInt", base=16) -WORD = Literal("WORD", "UInt", base=16) -DWORD = Literal("DWORD", "UInt", base=16) - -BOOL = Alias("BOOL", Bool) - -LPLONG = Pointer(LONG) -LPWORD = Pointer(WORD) -LPDWORD = Pointer(DWORD) -LPBOOL = Pointer(BOOL) -LPSIZE = LPDWORD - -LPSTR = CString -LPCSTR = Const(CString) -LPWSTR = WString -LPCWSTR = Const(WString) - -LARGE_INTEGER = Struct("LARGE_INTEGER", [ - (LONGLONG, 'QuadPart'), -]) - -SIZE_T = Alias("SIZE_T", SizeT) - -HRESULT = Alias("HRESULT", Int) - -VOID = Void -PVOID = Opaque("PVOID") -LPVOID = PVOID -HANDLE = Opaque("HANDLE") -HWND = Opaque("HWND") -HDC = Opaque("HDC") -HMONITOR = Opaque("HMONITOR") - -GUID = Struct("GUID", [ - (DWORD, "Data1"), - (WORD, "Data2"), - (WORD, "Data3"), - (BYTE, "Data4[0]"), - (BYTE, "Data4[1]"), - (BYTE, "Data4[2]"), - (BYTE, "Data4[3]"), - (BYTE, "Data4[4]"), - (BYTE, "Data4[5]"), - (BYTE, "Data4[6]"), - (BYTE, "Data4[7]"), -]) -LPGUID = Pointer(GUID) - -#REFGUID = Alias("REFGUID", Pointer(GUID)) -REFGUID = Alias("REFGUID", GUID) - -IID = Alias("IID", GUID) -#REFIID = Alias("REFIID", Pointer(IID)) -REFIID = Alias("REFIID", IID) - -CLSID = Alias("CLSID", GUID) -#REFCLSID = Alias("REFCLSID", Pointer(CLSID)) -REFCLSID = Alias("REFCLSID", CLSID) - -LUID = Struct("LUID", [ - (DWORD, "LowPart"), - (LONG, "HighPart"), -]) - -POINT = Struct("POINT", ( - (LONG, "x"), - (LONG, "y"), -)) -LPPOINT = Pointer(POINT) - -RECT = Struct("RECT", ( - (LONG, "left"), - (LONG, "top"), - (LONG, "right"), - (LONG, "bottom"), -)) -LPRECT = Pointer(RECT) - -PALETTEENTRY = Struct("PALETTEENTRY", ( - (BYTE, "peRed"), - (BYTE, "peGreen"), - (BYTE, "peBlue"), - (BYTE, "peFlags"), -)) -LPPALETTEENTRY = Pointer(PALETTEENTRY) - - -RGNDATAHEADER = Struct("RGNDATAHEADER", [ - (DWORD, "dwSize"), - (DWORD, "iType"), - (DWORD, "nCount"), - (DWORD, "nRgnSize"), - (RECT, "rcBound"), -]) - -RGNDATA = Struct("RGNDATA", [ - (RGNDATAHEADER, "rdh"), - #(Char, "Buffer[1]"), -]) -LPRGNDATA = Pointer(RGNDATA) - -HMODULE = Opaque("HMODULE") - -IUnknown = Interface("IUnknown") - -IUnknown.methods = ( - Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(OpaquePointer(Void)), "ppvObj"))), - Method(ULONG, "AddRef", ()), - Method(ULONG, "Release", ()), -) - - -class DllFunction(Function): - - def get_true_pointer(self): - ptype = self.pointer_type() - pvalue = self.pointer_value() - print ' if(!g_hDll) {' - print ' g_hDll = LoadLibrary(g_szDll);' - print ' if(!g_hDll)' - self.fail_impl() - print ' }' - print ' if(!%s) {' % (pvalue,) - print ' %s = (%s)GetProcAddress(g_hDll, "%s");' % (pvalue, ptype, self.name) - print ' if(!%s)' % (pvalue,) - self.fail_impl() - print ' }' - - -class Dll: - - def __init__(self, name): - self.name = name - self.functions = [] - if self not in towrap: - towrap.append(self) - - def wrap_name(self): - return "Wrap" + self.name - - def wrap_pre_decl(self): - pass - - def wrap_decl(self): - print 'static HINSTANCE g_hDll = NULL;' - print 'static TCHAR g_szDll[MAX_PATH] = {0};' - print - print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);' - print - for function in self.functions: - function.wrap_decl() - print - - def wrap_impl(self): - print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {' - print r' switch(fdwReason) {' - print r' case DLL_PROCESS_ATTACH:' - print r' if(!GetSystemDirectory(g_szDll, MAX_PATH))' - print r' return FALSE;' - print r' _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name - print r' Log::Open("%s");' % self.name - print r' case DLL_THREAD_ATTACH:' - print r' return TRUE;' - print r' case DLL_THREAD_DETACH:' - print r' return TRUE;' - print r' case DLL_PROCESS_DETACH:' - print r' Log::Close();' - print r' if(g_hDll) {' - print r' FreeLibrary(g_hDll);' - print r' g_hDll = NULL;' - print r' }' - print r' return TRUE;' - print r' }' - print r' (void)hinstDLL;' - print r' (void)lpvReserved;' - print r' return TRUE;' - print r'}' - print - for function in self.functions: - function.wrap_impl() - print -