From f26b2735574c46a768a05213659e302dce079172 Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Sat, 23 Jun 2007 09:57:34 +0000 Subject: [PATCH] simplefly Main_DirectDraw_QueryInterface code svn path=/trunk/; revision=27266 --- reactos/dll/directx/ddraw/Ddraw/ddraw_main.c | 147 ++++++++----------- 1 file changed, 61 insertions(+), 86 deletions(-) diff --git a/reactos/dll/directx/ddraw/Ddraw/ddraw_main.c b/reactos/dll/directx/ddraw/Ddraw/ddraw_main.c index 0b212fd5aed..11c3ac46f03 100644 --- a/reactos/dll/directx/ddraw/Ddraw/ddraw_main.c +++ b/reactos/dll/directx/ddraw/Ddraw/ddraw_main.c @@ -14,6 +14,8 @@ * table to right version of the functions */ + + #include "rosdraw.h" #include @@ -21,6 +23,22 @@ /* PSEH for SEH Support */ #include + + +LPDDRAWI_DIRECTDRAW_INT +internal_directdraw_int_alloc(LPDDRAWI_DIRECTDRAW_INT This) +{ + LPDDRAWI_DIRECTDRAW_INT newThis; + DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); + if (newThis) + { + newThis->lpLcl = This->lpLcl; + newThis->lpLink = This; + } + + return newThis; +} + HRESULT WINAPI Main_DirectDraw_QueryInterface (LPDDRAWI_DIRECTDRAW_INT This, REFIID id, @@ -40,109 +58,66 @@ Main_DirectDraw_QueryInterface (LPDDRAWI_DIRECTDRAW_INT This, { if (This->lpVtbl != &DirectDraw7_Vtable) { - LPDDRAWI_DIRECTDRAW_INT newThis; - DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); + This = internal_directdraw_int_alloc(This); + if (!This) + { + retVal = DDERR_OUTOFVIDEOMEMORY; + _SEH_LEAVE; + } + } - if (newThis == NULL) - { - retVal = DDERR_OUTOFMEMORY; - } - else - { - /* DirectDraw7 Vtable */ - newThis->lpVtbl = &DirectDraw7_Vtable; - newThis->lpLcl = This->lpLcl; - newThis->lpLink = This; - *obj = &newThis->lpVtbl; - Main_DirectDraw_AddRef(newThis); - } - } - else - { - *obj = This; - Main_DirectDraw_AddRef(This); - } + This->lpVtbl = &DirectDraw7_Vtable; + *obj = This; + Main_DirectDraw_AddRef(This); } else if (IsEqualGUID(&IID_IDirectDraw4, id)) { if (This->lpVtbl != &DirectDraw4_Vtable) { - LPDDRAWI_DIRECTDRAW_INT newThis; - DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); + This = internal_directdraw_int_alloc(This); + if (!This) + { + retVal = DDERR_OUTOFVIDEOMEMORY; + _SEH_LEAVE; + } + } - if (newThis == NULL) - { - retVal = DDERR_OUTOFMEMORY; - } - else - { - /* DirectDraw4 Vtable */ - newThis->lpVtbl = &DirectDraw4_Vtable; - newThis->lpLcl = This->lpLcl; - newThis->lpLink = This; - *obj = &newThis->lpVtbl; - Main_DirectDraw_AddRef(newThis); - } - } - else - { - *obj = This; - Main_DirectDraw_AddRef(This); - } + This->lpVtbl = &DirectDraw2_Vtable; + *obj = This; + Main_DirectDraw_AddRef(This); } - else if (IsEqualGUID(&IID_IDirectDraw2, id)) - { - if (This->lpVtbl != &DirectDraw2_Vtable) - { - LPDDRAWI_DIRECTDRAW_INT newThis; - DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); - if (newThis == NULL) - { - retVal = DDERR_OUTOFMEMORY; - } - else - { - /* DirectDraw4 Vtable */ - newThis->lpVtbl = &DirectDraw2_Vtable; - newThis->lpLcl = This->lpLcl; - newThis->lpLink = This; - *obj = &newThis->lpVtbl; - Main_DirectDraw_AddRef(newThis); - } - } - else + else if (IsEqualGUID(&IID_IDirectDraw4, id)) + { + if (This->lpVtbl != &DirectDraw4_Vtable) { - *obj = This; - Main_DirectDraw_AddRef(This); + This = internal_directdraw_int_alloc(This); + if (!This) + { + retVal = DDERR_OUTOFVIDEOMEMORY; + _SEH_LEAVE; + } } + + This->lpVtbl = &DirectDraw2_Vtable; + *obj = This; + Main_DirectDraw_AddRef(This); } else if (IsEqualGUID(&IID_IDirectDraw, id)) { if (This->lpVtbl != &DirectDraw_Vtable) { - LPDDRAWI_DIRECTDRAW_INT newThis; - DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); + This = internal_directdraw_int_alloc(This); + if (!This) + { + retVal = DDERR_OUTOFVIDEOMEMORY; + _SEH_LEAVE; + } + } - if (newThis == NULL) - { - retVal = DDERR_OUTOFMEMORY; - } - else - { - /* DirectDraw Vtable */ - newThis->lpVtbl = &DirectDraw_Vtable; - newThis->lpLcl = This->lpLcl; - newThis->lpLink = This; - *obj = &newThis->lpVtbl; - Main_DirectDraw_AddRef(newThis); - } - } - else - { - *obj = This; - Main_DirectDraw_AddRef(This); - } + This->lpVtbl = &DirectDraw_Vtable; + *obj = This; + Main_DirectDraw_AddRef(This); } else {