dmband: Remove the extraneous IUnknown from DirectMusicBand.

Also lock/unlock the module only on creation/destruction of the object.
This commit is contained in:
Michael Stefaniuc 2014-01-30 01:06:43 +01:00 committed by Alexandre Julliard
parent 868ad7dc72
commit c1b3b58eac
2 changed files with 50 additions and 76 deletions

View File

@ -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);
/* DirectMusicBandImpl IDirectMusicBand part: */
static HRESULT WINAPI IDirectMusicBandImpl_QueryInterface(IDirectMusicBand *iface, REFIID riid,
void **ret_iface)
{
IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(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;
}
TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
*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;
}
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: */
static HRESULT WINAPI IDirectMusicBandImpl_QueryInterface(IDirectMusicBand *iface, REFIID riid,
void **ppobj)
{
IDirectMusicBandImpl *This = impl_from_IDirectMusicBand(iface);
return IUnknown_QueryInterface ((LPUNKNOWN)&This->UnknownVtbl, riid, ppobj);
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;
}

View File

@ -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;