Michael Stefaniuc : dplayx: Simplify the creation of an IDirectPlaySPImpl object.

Alexandre Julliard julliard at winehq.org
Thu Sep 5 13:28:19 CDT 2013


Module: wine
Branch: master
Commit: b80ab3357168123c3cfb35082159c491973f1474
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b80ab3357168123c3cfb35082159c491973f1474

Author: Michael Stefaniuc <mstefani at redhat.de>
Date:   Thu Sep  5 00:01:20 2013 +0200

dplayx: Simplify the creation of an IDirectPlaySPImpl object.

---

 dlls/dplayx/dplay.c        |    4 +--
 dlls/dplayx/dplay_global.h |    2 +-
 dlls/dplayx/dplaysp.c      |   55 ++++++++++++++++---------------------------
 3 files changed, 23 insertions(+), 38 deletions(-)

diff --git a/dlls/dplayx/dplay.c b/dlls/dplayx/dplay.c
index 94ba844..20899d5 100644
--- a/dlls/dplayx/dplay.c
+++ b/dlls/dplayx/dplay.c
@@ -173,9 +173,7 @@ static BOOL DP_CreateDirectPlay2( LPVOID lpDP )
   This->dp2->spData.lpCB->dwVersion = DPSP_MAJORVERSION;
 
   /* This is the pointer to the service provider */
-  if( FAILED( DPSP_CreateInterface( &IID_IDirectPlaySP,
-                                    (LPVOID*)&This->dp2->spData.lpISP, This ) )
-    )
+  if ( FAILED( dplaysp_create( &IID_IDirectPlaySP, (void**)&This->dp2->spData.lpISP, This ) ) )
   {
     /* FIXME: Memory leak */
     return FALSE;
diff --git a/dlls/dplayx/dplay_global.h b/dlls/dplayx/dplay_global.h
index dca6396..7def46b 100644
--- a/dlls/dplayx/dplay_global.h
+++ b/dlls/dplayx/dplay_global.h
@@ -208,7 +208,7 @@ extern LPVOID DPSP_CreateSPPlayerData(void) DECLSPEC_HIDDEN;
 
 extern HRESULT dplay_create( REFIID riid, void **ppv ) DECLSPEC_HIDDEN;
 extern HRESULT dplobby_create( REFIID riid, void **ppv ) DECLSPEC_HIDDEN;
-extern HRESULT DPSP_CreateInterface( REFIID riid, void **ppvObj, IDirectPlayImpl *dp ) DECLSPEC_HIDDEN;
+extern HRESULT dplaysp_create( REFIID riid, void **ppv, IDirectPlayImpl *dp ) DECLSPEC_HIDDEN;
 extern HRESULT dplobbysp_create( REFIID riid, void **ppv, IDirectPlayImpl *dp ) DECLSPEC_HIDDEN;
 
 #endif /* __WINE_DPLAY_GLOBAL_INCLUDED */
diff --git a/dlls/dplayx/dplaysp.c b/dlls/dplayx/dplaysp.c
index e8269df..25cb7c4 100644
--- a/dlls/dplayx/dplaysp.c
+++ b/dlls/dplayx/dplaysp.c
@@ -44,9 +44,6 @@ typedef struct IDirectPlaySPImpl
   IDirectPlayImpl *dplay; /* FIXME: This should perhaps be iface not impl */
 } IDirectPlaySPImpl;
 
-/* Forward declaration of virtual tables */
-static const IDirectPlaySPVtbl directPlaySPVT;
-
 /* This structure is passed to the DP object for safe keeping */
 typedef struct tagDP_SPPLAYERDATA
 {
@@ -57,37 +54,6 @@ typedef struct tagDP_SPPLAYERDATA
   DWORD  dwPlayerRemoteDataSize;
 } DP_SPPLAYERDATA, *LPDP_SPPLAYERDATA;
 
-/* Create the SP interface */
-HRESULT DPSP_CreateInterface( REFIID riid, void **ppvObj, IDirectPlayImpl *dp )
-{
-  TRACE( " for %s\n", debugstr_guid( riid ) );
-
-  *ppvObj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
-                       sizeof( IDirectPlaySPImpl ) );
-
-  if( *ppvObj == NULL )
-  {
-    return DPERR_OUTOFMEMORY;
-  }
-
-  if( IsEqualGUID( &IID_IDirectPlaySP, riid ) )
-  {
-    IDirectPlaySPImpl *This = *ppvObj;
-    This->IDirectPlaySP_iface.lpVtbl = &directPlaySPVT;
-    This->dplay = dp;
-  }
-  else
-  {
-    /* Unsupported interface */
-    HeapFree( GetProcessHeap(), 0, *ppvObj );
-    *ppvObj = NULL;
-
-    return E_NOINTERFACE;
-  }
-
-  IDirectPlaySP_AddRef( (LPDIRECTPLAYSP)*ppvObj );
-  return S_OK;
-}
 
 static inline IDirectPlaySPImpl *impl_from_IDirectPlaySP( IDirectPlaySP *iface )
 {
@@ -717,6 +683,27 @@ static const IDirectPlaySPVtbl directPlaySPVT =
   IDirectPlaySPImpl_SendComplete
 };
 
+HRESULT dplaysp_create( REFIID riid, void **ppv, IDirectPlayImpl *dp )
+{
+  IDirectPlaySPImpl *obj;
+  HRESULT hr;
+
+  TRACE( "(%s, %p)\n", debugstr_guid( riid ), ppv );
+
+  *ppv = NULL;
+  obj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *obj ) );
+  if ( !obj )
+    return DPERR_OUTOFMEMORY;
+
+  obj->IDirectPlaySP_iface.lpVtbl = &directPlaySPVT;
+  obj->ref = 1;
+  obj->dplay = dp;
+
+  hr = IDirectPlaySP_QueryInterface( &obj->IDirectPlaySP_iface, riid, ppv );
+  IDirectPlaySP_Release( &obj->IDirectPlaySP_iface );
+
+  return hr;
+}
 
 /* DP external interfaces to call into DPSP interface */
 




More information about the wine-cvs mailing list