From c1b3b58eac830c83200def7642dac0180e261822 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Thu, 30 Jan 2014 01:06:43 +0100 Subject: [PATCH] dmband: Remove the extraneous IUnknown from DirectMusicBand. Also lock/unlock the module only on creation/destruction of the object. --- dlls/dmband/band.c | 124 ++++++++++++++--------------------- dlls/dmband/dmband_private.h | 2 - 2 files changed, 50 insertions(+), 76 deletions(-) diff --git a/dlls/dmband/band.c b/dlls/dmband/band.c index a985977a0eb..97e7c300cd2 100644 --- a/dlls/dmband/band.c +++ b/dlls/dmband/band.c @@ -31,83 +31,55 @@ static inline IDirectMusicBandImpl *impl_from_IDirectMusicBand(IDirectMusicBand return CONTAINING_RECORD(iface, IDirectMusicBandImpl, IDirectMusicBand_iface); } -/* IDirectMusicBandImpl IUnknown part: */ -static HRESULT WINAPI IDirectMusicBandImpl_IUnknown_QueryInterface (LPUNKNOWN iface, REFIID riid, LPVOID *ppobj) { - ICOM_THIS_MULTI(IDirectMusicBandImpl, UnknownVtbl, iface); - - TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj); - if (IsEqualIID (riid, &IID_IUnknown)) { - *ppobj = &This->UnknownVtbl; - IUnknown_AddRef (iface); - return S_OK; - } else if (IsEqualIID (riid, &IID_IDirectMusicBand)) { - *ppobj = &This->IDirectMusicBand_iface; - IUnknown_AddRef (iface); - return S_OK; - } else if (IsEqualIID (riid, &IID_IDirectMusicObject)) { - *ppobj = &This->ObjectVtbl; - IUnknown_AddRef (iface); - return S_OK; - } else if (IsEqualIID (riid, &IID_IPersistStream)) { - *ppobj = &This->PersistStreamVtbl; - IUnknown_AddRef (iface); - return S_OK; - } - - WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj); - return E_NOINTERFACE; -} - -static ULONG WINAPI IDirectMusicBandImpl_IUnknown_AddRef (LPUNKNOWN iface) { - ICOM_THIS_MULTI(IDirectMusicBandImpl, UnknownVtbl, iface); - ULONG ref = InterlockedIncrement(&This->ref); - - TRACE("(%p) : AddRef from %d\n", This, ref - 1); - - DMBAND_LockModule(); - - return ref; -} - -static ULONG WINAPI IDirectMusicBandImpl_IUnknown_Release (LPUNKNOWN iface) { - ICOM_THIS_MULTI(IDirectMusicBandImpl, UnknownVtbl, iface); - ULONG ref = InterlockedDecrement(&This->ref); - - TRACE("(%p) : ReleaseRef to %d\n", This, ref); - - if (ref == 0) { - HeapFree(GetProcessHeap(), 0, This); - } - - DMBAND_UnlockModule(); - - return ref; -} - -static const IUnknownVtbl DirectMusicBand_Unknown_Vtbl = { - IDirectMusicBandImpl_IUnknown_QueryInterface, - IDirectMusicBandImpl_IUnknown_AddRef, - IDirectMusicBandImpl_IUnknown_Release -}; - -/* IDirectMusicBandImpl IDirectMusicBand part: */ +/* DirectMusicBandImpl IDirectMusicBand part: */ static HRESULT WINAPI IDirectMusicBandImpl_QueryInterface(IDirectMusicBand *iface, REFIID riid, - void **ppobj) + void **ret_iface) { IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface); - return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj); + + TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface); + + *ret_iface = NULL; + + if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDirectMusicBand)) + *ret_iface = iface; + else if (IsEqualIID(riid, &IID_IDirectMusicObject)) + *ret_iface = &This->ObjectVtbl; + else if (IsEqualIID(riid, &IID_IPersistStream)) + *ret_iface = &This->PersistStreamVtbl; + else { + WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ret_iface); + return E_NOINTERFACE; + } + + IDirectMusicBand_AddRef((IUnknown*)*ret_iface); + return S_OK; } static ULONG WINAPI IDirectMusicBandImpl_AddRef(IDirectMusicBand *iface) { IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface); - return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl); + LONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) ref=%d\n", This, ref); + + return ref; } static ULONG WINAPI IDirectMusicBandImpl_Release(IDirectMusicBand *iface) { IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface); - return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl); + LONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) ref=%d\n", This, ref); + + if (!ref) { + HeapFree(GetProcessHeap(), 0, This->pDesc); + HeapFree(GetProcessHeap(), 0, This); + DMBAND_UnlockModule(); + } + + return ref; } static HRESULT WINAPI IDirectMusicBandImpl_CreateSegment(IDirectMusicBand *iface, @@ -146,17 +118,17 @@ static const IDirectMusicBandVtbl dmband_vtbl = { /* IDirectMusicBandImpl IDirectMusicObject part: */ static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) { ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface); - return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj); + return IDirectMusicBand_QueryInterface(&This->IDirectMusicBand_iface, riid, ppobj); } static ULONG WINAPI IDirectMusicBandImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) { ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface); - return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl); + return IDirectMusicBand_AddRef(&This->IDirectMusicBand_iface); } static ULONG WINAPI IDirectMusicBandImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) { ICOM_THIS_MULTI(IDirectMusicBandImpl, ObjectVtbl, iface); - return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl); + return IDirectMusicBand_Release(&This->IDirectMusicBand_iface); } static HRESULT WINAPI IDirectMusicBandImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) { @@ -360,17 +332,17 @@ static const IDirectMusicObjectVtbl DirectMusicBand_Object_Vtbl = { /* IDirectMusicBandImpl IPersistStream part: */ static HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) { ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface); - return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj); + return IDirectMusicBand_QueryInterface(&This->IDirectMusicBand_iface, riid, ppobj); } static ULONG WINAPI IDirectMusicBandImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface) { ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface); - return IUnknown_AddRef ((LPUNKNOWN)&This->UnknownVtbl); + return IDirectMusicBand_AddRef(&This->IDirectMusicBand_iface); } static ULONG WINAPI IDirectMusicBandImpl_IPersistStream_Release (LPPERSISTSTREAM iface) { ICOM_THIS_MULTI(IDirectMusicBandImpl, PersistStreamVtbl, iface); - return IUnknown_Release ((LPUNKNOWN)&This->UnknownVtbl); + return IDirectMusicBand_Release(&This->IDirectMusicBand_iface); } static HRESULT WINAPI IDirectMusicBandImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) { @@ -705,13 +677,13 @@ static const IPersistStreamVtbl DirectMusicBand_PersistStream_Vtbl = { HRESULT WINAPI create_dmband(REFIID lpcGUID, void **ppobj) { IDirectMusicBandImpl* obj; - + HRESULT hr; + obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBandImpl)); if (NULL == obj) { *ppobj = NULL; return E_OUTOFMEMORY; } - obj->UnknownVtbl = &DirectMusicBand_Unknown_Vtbl; obj->IDirectMusicBand_iface.lpVtbl = &dmband_vtbl; obj->ObjectVtbl = &DirectMusicBand_Object_Vtbl; obj->PersistStreamVtbl = &DirectMusicBand_PersistStream_Vtbl; @@ -719,8 +691,12 @@ HRESULT WINAPI create_dmband(REFIID lpcGUID, void **ppobj) DM_STRUCT_INIT(obj->pDesc); obj->pDesc->dwValidData |= DMUS_OBJ_CLASS; obj->pDesc->guidClass = CLSID_DirectMusicBand; - obj->ref = 0; /* will be inited by QueryInterface */ + obj->ref = 1; list_init (&obj->Instruments); - return IDirectMusicBandImpl_IUnknown_QueryInterface ((LPUNKNOWN)&obj->UnknownVtbl, lpcGUID, ppobj); + DMBAND_LockModule(); + hr = IDirectMusicBand_QueryInterface(&obj->IDirectMusicBand_iface, lpcGUID, ppobj); + IDirectMusicBand_Release(&obj->IDirectMusicBand_iface); + + return hr; } diff --git a/dlls/dmband/dmband_private.h b/dlls/dmband/dmband_private.h index 8dc0b1216c7..6be6ae803a5 100644 --- a/dlls/dmband/dmband_private.h +++ b/dlls/dmband/dmband_private.h @@ -86,8 +86,6 @@ typedef struct _DMUS_PRIVATE_BAND { * IDirectMusicBandImpl implementation structure */ struct IDirectMusicBandImpl { - /* IUnknown fields */ - const IUnknownVtbl *UnknownVtbl; IDirectMusicBand IDirectMusicBand_iface; const IDirectMusicObjectVtbl *ObjectVtbl; const IPersistStreamVtbl *PersistStreamVtbl;