[PATCH 2/7] ddrawex: COM cleanup for the IDirectDrawFactory iface.

Michael Stefaniuc mstefani at redhat.de
Sun Jan 23 14:02:50 CST 2011


---
 dlls/ddrawex/ddrawex_private.h |    9 ---------
 dlls/ddrawex/main.c            |   37 ++++++++++++++++++++++++-------------
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/dlls/ddrawex/ddrawex_private.h b/dlls/ddrawex/ddrawex_private.h
index 079b26c..34608c6 100644
--- a/dlls/ddrawex/ddrawex_private.h
+++ b/dlls/ddrawex/ddrawex_private.h
@@ -44,15 +44,6 @@ DECLARE_INTERFACE_(IDirectDrawFactory, IUnknown)
 #endif
 
 
-/******************************************************************************
- * DirectDrawFactory implementation
- ******************************************************************************/
-typedef struct
-{
-    const IDirectDrawFactoryVtbl *lpVtbl;
-    LONG ref;
-} IDirectDrawFactoryImpl;
-
 HRESULT WINAPI IDirectDrawFactoryImpl_CreateDirectDraw(IDirectDrawFactory* iface,
     GUID * pGUID, HWND hWnd, DWORD dwCoopLevelFlags, DWORD dwReserved, IUnknown *pUnkOuter,
     IDirectDraw **ppDirectDraw);
diff --git a/dlls/ddrawex/main.c b/dlls/ddrawex/main.c
index b5923e2..7b32323 100644
--- a/dlls/ddrawex/main.c
+++ b/dlls/ddrawex/main.c
@@ -150,16 +150,28 @@ static const IClassFactoryVtbl IClassFactory_Vtbl =
 };
 
 
+/******************************************************************************
+ * DirectDrawFactory implementation
+ ******************************************************************************/
+typedef struct
+{
+    IDirectDrawFactory IDirectDrawFactory_iface;
+    LONG ref;
+} IDirectDrawFactoryImpl;
+
+static inline IDirectDrawFactoryImpl *impl_from_IDirectDrawFactory(IDirectDrawFactory *iface)
+{
+    return CONTAINING_RECORD(iface, IDirectDrawFactoryImpl, IDirectDrawFactory_iface);
+}
+
 /*******************************************************************************
  * IDirectDrawFactory::QueryInterface
  *
  *******************************************************************************/
-static HRESULT WINAPI
-IDirectDrawFactoryImpl_QueryInterface(IDirectDrawFactory *iface,
-                    REFIID riid,
-                    void **obj)
+static HRESULT WINAPI IDirectDrawFactoryImpl_QueryInterface(IDirectDrawFactory *iface, REFIID riid,
+        void **obj)
 {
-    IDirectDrawFactoryImpl *This = (IDirectDrawFactoryImpl*) iface;
+    IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
 
     TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), obj);
 
@@ -179,10 +191,9 @@ IDirectDrawFactoryImpl_QueryInterface(IDirectDrawFactory *iface,
  * IDirectDrawFactory::AddRef
  *
  *******************************************************************************/
-static ULONG WINAPI
-IDirectDrawFactoryImpl_AddRef(IDirectDrawFactory *iface)
+static ULONG WINAPI IDirectDrawFactoryImpl_AddRef(IDirectDrawFactory *iface)
 {
-    IDirectDrawFactoryImpl *This = (IDirectDrawFactoryImpl*) iface;
+    IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
     ULONG ref = InterlockedIncrement(&This->ref);
 
     TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
@@ -194,11 +205,11 @@ IDirectDrawFactoryImpl_AddRef(IDirectDrawFactory *iface)
  * IDirectDrawFactory::Release
  *
  *******************************************************************************/
-static ULONG WINAPI
-IDirectDrawFactoryImpl_Release(IDirectDrawFactory *iface)
+static ULONG WINAPI IDirectDrawFactoryImpl_Release(IDirectDrawFactory *iface)
 {
-    IDirectDrawFactoryImpl *This = (IDirectDrawFactoryImpl*) iface;
+    IDirectDrawFactoryImpl *This = impl_from_IDirectDrawFactory(iface);
     ULONG ref = InterlockedDecrement(&This->ref);
+
     TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
 
     if (ref == 0)
@@ -255,9 +266,9 @@ CreateDirectDrawFactory(IUnknown* UnkOuter, REFIID iid, void **obj)
         return E_OUTOFMEMORY;
     }
 
-    This->lpVtbl = &IDirectDrawFactory_Vtbl;
+    This->IDirectDrawFactory_iface.lpVtbl = &IDirectDrawFactory_Vtbl;
 
-    hr = IDirectDrawFactory_QueryInterface((IDirectDrawFactory *)This, iid,  obj);
+    hr = IDirectDrawFactory_QueryInterface(&This->IDirectDrawFactory_iface, iid,  obj);
 
     if (FAILED(hr))
         HeapFree(GetProcessHeap(), 0, This);
-- 
1.7.3.4



More information about the wine-patches mailing list