Commit 9ab1cfb5 authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

dmloader: COM cleanup for IDirectMusicContainer.

parent 8a15ea11
...@@ -27,14 +27,24 @@ WINE_DECLARE_DEBUG_CHANNEL(dmdump); ...@@ -27,14 +27,24 @@ WINE_DECLARE_DEBUG_CHANNEL(dmdump);
#define DMUS_MAX_NAME_SIZE DMUS_MAX_NAME*sizeof(WCHAR) #define DMUS_MAX_NAME_SIZE DMUS_MAX_NAME*sizeof(WCHAR)
#define DMUS_MAX_FILENAME_SIZE DMUS_MAX_FILENAME*sizeof(WCHAR) #define DMUS_MAX_FILENAME_SIZE DMUS_MAX_FILENAME*sizeof(WCHAR)
static ULONG WINAPI IDirectMusicContainerImpl_IDirectMusicContainer_AddRef (LPDIRECTMUSICCONTAINER iface);
static ULONG WINAPI IDirectMusicContainerImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface);
static ULONG WINAPI IDirectMusicContainerImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface);
/***************************************************************************** /*****************************************************************************
* IDirectMusicContainerImpl implementation * IDirectMusicContainerImpl implementation
*/ */
/* IUnknown/IDirectMusicContainer part: */ typedef struct IDirectMusicContainerImpl {
IDirectMusicContainer IDirectMusicContainer_iface;
const IDirectMusicObjectVtbl *ObjectVtbl;
const IPersistStreamVtbl *PersistStreamVtbl;
LONG ref;
IStream *pStream;
DMUS_IO_CONTAINER_HEADER Header; /* header */
struct list *pContainedObjects; /* data */
DMUS_OBJECTDESC Desc;
} IDirectMusicContainerImpl;
static inline IDirectMusicContainerImpl *impl_from_IDirectMusicContainer(IDirectMusicContainer *iface)
{
return CONTAINING_RECORD(iface, IDirectMusicContainerImpl, IDirectMusicContainer_iface);
}
static HRESULT destroy_dmcontainer(IDirectMusicContainerImpl *This) static HRESULT destroy_dmcontainer(IDirectMusicContainerImpl *This)
{ {
...@@ -72,52 +82,59 @@ static HRESULT destroy_dmcontainer(IDirectMusicContainerImpl *This) ...@@ -72,52 +82,59 @@ static HRESULT destroy_dmcontainer(IDirectMusicContainerImpl *This)
return S_OK; return S_OK;
} }
static HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface (LPDIRECTMUSICCONTAINER iface, REFIID riid, LPVOID *ppobj) { static HRESULT WINAPI IDirectMusicContainerImpl_QueryInterface(IDirectMusicContainer *iface, REFIID riid, void **ret_iface)
ICOM_THIS_MULTI(IDirectMusicContainerImpl, ContainerVtbl, iface); {
IDirectMusicContainerImpl *This = impl_from_IDirectMusicContainer(iface);
TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
if (IsEqualIID (riid, &IID_IUnknown) || TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ret_iface);
IsEqualIID (riid, &IID_IDirectMusicContainer)) {
*ppobj = &This->ContainerVtbl; if (IsEqualIID (riid, &IID_IUnknown) || IsEqualIID (riid, &IID_IDirectMusicContainer))
IDirectMusicContainerImpl_IDirectMusicContainer_AddRef ((LPDIRECTMUSICCONTAINER)&This->ContainerVtbl); *ret_iface = &This->IDirectMusicContainer_iface;
return S_OK; else if (IsEqualIID (riid, &IID_IDirectMusicObject))
} else if (IsEqualIID (riid, &IID_IDirectMusicObject)) { *ret_iface = &This->ObjectVtbl;
*ppobj = &This->ObjectVtbl; else if (IsEqualIID (riid, &IID_IPersistStream))
IDirectMusicContainerImpl_IDirectMusicObject_AddRef ((LPDIRECTMUSICOBJECT)&This->ObjectVtbl); *ret_iface = &This->PersistStreamVtbl;
return S_OK; else {
} else if (IsEqualIID (riid, &IID_IPersistStream)) { WARN("Unknown interface %s\n", debugstr_dmguid(riid));
*ppobj = &This->PersistStreamVtbl; *ret_iface = NULL;
IDirectMusicContainerImpl_IPersistStream_AddRef ((LPPERSISTSTREAM)&This->PersistStreamVtbl); return E_NOINTERFACE;
return S_OK;
} }
WARN(": not found\n"); IUnknown_AddRef((IUnknown*)*ret_iface);
return E_NOINTERFACE; return S_OK;
} }
static ULONG WINAPI IDirectMusicContainerImpl_IDirectMusicContainer_AddRef (LPDIRECTMUSICCONTAINER iface) { static ULONG WINAPI IDirectMusicContainerImpl_AddRef(IDirectMusicContainer *iface)
ICOM_THIS_MULTI(IDirectMusicContainerImpl, ContainerVtbl, iface); {
TRACE("(%p): AddRef from %d\n", This, This->dwRef); IDirectMusicContainerImpl *This = impl_from_IDirectMusicContainer(iface);
return InterlockedIncrement (&This->dwRef); LONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) ref=%d\n", This, ref);
return ref;
} }
static ULONG WINAPI IDirectMusicContainerImpl_IDirectMusicContainer_Release (LPDIRECTMUSICCONTAINER iface) { static ULONG WINAPI IDirectMusicContainerImpl_Release(IDirectMusicContainer *iface)
ICOM_THIS_MULTI(IDirectMusicContainerImpl, ContainerVtbl, iface); {
IDirectMusicContainerImpl *This = impl_from_IDirectMusicContainer(iface);
LONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) ref=%d\n", This, ref);
DWORD dwRef = InterlockedDecrement (&This->dwRef); if (!ref) {
TRACE("(%p): ReleaseRef to %d\n", This, dwRef);
if (dwRef == 0) {
if (This->pStream) if (This->pStream)
destroy_dmcontainer(This); destroy_dmcontainer(This);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
unlock_module(); unlock_module();
} }
return dwRef; return ref;
} }
static HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicContainer_EnumObject (LPDIRECTMUSICCONTAINER iface, REFGUID rguidClass, DWORD dwIndex, LPDMUS_OBJECTDESC pDesc, WCHAR* pwszAlias) { static HRESULT WINAPI IDirectMusicContainerImpl_EnumObject(IDirectMusicContainer *iface,
ICOM_THIS_MULTI(IDirectMusicContainerImpl, ContainerVtbl, iface); REFGUID rguidClass, DWORD dwIndex, DMUS_OBJECTDESC *pDesc, WCHAR *pwszAlias)
{
IDirectMusicContainerImpl *This = impl_from_IDirectMusicContainer(iface);
struct list *pEntry; struct list *pEntry;
LPWINE_CONTAINER_ENTRY pContainedObject; LPWINE_CONTAINER_ENTRY pContainedObject;
DWORD dwCount = 0; DWORD dwCount = 0;
...@@ -155,27 +172,27 @@ static HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicContainer_EnumObject ...@@ -155,27 +172,27 @@ static HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicContainer_EnumObject
return S_FALSE; return S_FALSE;
} }
static const IDirectMusicContainerVtbl DirectMusicContainer_Container_Vtbl = { static const IDirectMusicContainerVtbl dmcontainer_vtbl = {
IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface, IDirectMusicContainerImpl_QueryInterface,
IDirectMusicContainerImpl_IDirectMusicContainer_AddRef, IDirectMusicContainerImpl_AddRef,
IDirectMusicContainerImpl_IDirectMusicContainer_Release, IDirectMusicContainerImpl_Release,
IDirectMusicContainerImpl_IDirectMusicContainer_EnumObject IDirectMusicContainerImpl_EnumObject
}; };
/* IDirectMusicObject part: */ /* IDirectMusicObject part: */
static HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) { static HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicObject_QueryInterface (LPDIRECTMUSICOBJECT iface, REFIID riid, LPVOID *ppobj) {
ICOM_THIS_MULTI(IDirectMusicContainerImpl, ObjectVtbl, iface); ICOM_THIS_MULTI(IDirectMusicContainerImpl, ObjectVtbl, iface);
return IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface ((LPDIRECTMUSICCONTAINER)&This->ContainerVtbl, riid, ppobj); return IDirectMusicContainerImpl_QueryInterface(&This->IDirectMusicContainer_iface, riid, ppobj);
} }
static ULONG WINAPI IDirectMusicContainerImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) { static ULONG WINAPI IDirectMusicContainerImpl_IDirectMusicObject_AddRef (LPDIRECTMUSICOBJECT iface) {
ICOM_THIS_MULTI(IDirectMusicContainerImpl, ObjectVtbl, iface); ICOM_THIS_MULTI(IDirectMusicContainerImpl, ObjectVtbl, iface);
return IDirectMusicContainerImpl_IDirectMusicContainer_AddRef ((LPDIRECTMUSICCONTAINER)&This->ContainerVtbl); return IDirectMusicContainer_AddRef(&This->IDirectMusicContainer_iface);
} }
static ULONG WINAPI IDirectMusicContainerImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) { static ULONG WINAPI IDirectMusicContainerImpl_IDirectMusicObject_Release (LPDIRECTMUSICOBJECT iface) {
ICOM_THIS_MULTI(IDirectMusicContainerImpl, ObjectVtbl, iface); ICOM_THIS_MULTI(IDirectMusicContainerImpl, ObjectVtbl, iface);
return IDirectMusicContainerImpl_IDirectMusicContainer_Release ((LPDIRECTMUSICCONTAINER)&This->ContainerVtbl); return IDirectMusicContainerImpl_Release(&This->IDirectMusicContainer_iface);
} }
static HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) { static HRESULT WINAPI IDirectMusicContainerImpl_IDirectMusicObject_GetDescriptor (LPDIRECTMUSICOBJECT iface, LPDMUS_OBJECTDESC pDesc) {
...@@ -439,17 +456,17 @@ static const IDirectMusicObjectVtbl DirectMusicContainer_Object_Vtbl = { ...@@ -439,17 +456,17 @@ static const IDirectMusicObjectVtbl DirectMusicContainer_Object_Vtbl = {
/* IPersistStream part: */ /* IPersistStream part: */
static HRESULT WINAPI IDirectMusicContainerImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) { static HRESULT WINAPI IDirectMusicContainerImpl_IPersistStream_QueryInterface (LPPERSISTSTREAM iface, REFIID riid, LPVOID *ppobj) {
ICOM_THIS_MULTI(IDirectMusicContainerImpl, PersistStreamVtbl, iface); ICOM_THIS_MULTI(IDirectMusicContainerImpl, PersistStreamVtbl, iface);
return IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface ((LPDIRECTMUSICCONTAINER)&This->ContainerVtbl, riid, ppobj); return IDirectMusicContainerImpl_QueryInterface(&This->IDirectMusicContainer_iface, riid, ppobj);
} }
static ULONG WINAPI IDirectMusicContainerImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface) { static ULONG WINAPI IDirectMusicContainerImpl_IPersistStream_AddRef (LPPERSISTSTREAM iface) {
ICOM_THIS_MULTI(IDirectMusicContainerImpl, PersistStreamVtbl, iface); ICOM_THIS_MULTI(IDirectMusicContainerImpl, PersistStreamVtbl, iface);
return IDirectMusicContainerImpl_IDirectMusicContainer_AddRef ((LPDIRECTMUSICCONTAINER)&This->ContainerVtbl); return IDirectMusicContainer_AddRef(&This->IDirectMusicContainer_iface);
} }
static ULONG WINAPI IDirectMusicContainerImpl_IPersistStream_Release (LPPERSISTSTREAM iface) { static ULONG WINAPI IDirectMusicContainerImpl_IPersistStream_Release (LPPERSISTSTREAM iface) {
ICOM_THIS_MULTI(IDirectMusicContainerImpl, PersistStreamVtbl, iface); ICOM_THIS_MULTI(IDirectMusicContainerImpl, PersistStreamVtbl, iface);
return IDirectMusicContainerImpl_IDirectMusicContainer_Release ((LPDIRECTMUSICCONTAINER)&This->ContainerVtbl); return IDirectMusicContainerImpl_Release(&This->IDirectMusicContainer_iface);
} }
static HRESULT WINAPI IDirectMusicContainerImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) { static HRESULT WINAPI IDirectMusicContainerImpl_IPersistStream_GetClassID (LPPERSISTSTREAM iface, CLSID* pClassID) {
...@@ -913,20 +930,24 @@ static const IPersistStreamVtbl DirectMusicContainer_PersistStream_Vtbl = { ...@@ -913,20 +930,24 @@ static const IPersistStreamVtbl DirectMusicContainer_PersistStream_Vtbl = {
HRESULT WINAPI create_dmcontainer(REFIID lpcGUID, void **ppobj) HRESULT WINAPI create_dmcontainer(REFIID lpcGUID, void **ppobj)
{ {
IDirectMusicContainerImpl* obj; IDirectMusicContainerImpl* obj;
HRESULT hr;
obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicContainerImpl)); obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicContainerImpl));
if (NULL == obj) { if (NULL == obj) {
*ppobj = NULL; *ppobj = NULL;
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
obj->ContainerVtbl = &DirectMusicContainer_Container_Vtbl; obj->IDirectMusicContainer_iface.lpVtbl = &dmcontainer_vtbl;
obj->ObjectVtbl = &DirectMusicContainer_Object_Vtbl; obj->ObjectVtbl = &DirectMusicContainer_Object_Vtbl;
obj->PersistStreamVtbl = &DirectMusicContainer_PersistStream_Vtbl; obj->PersistStreamVtbl = &DirectMusicContainer_PersistStream_Vtbl;
obj->dwRef = 0; /* will be inited by QueryInterface */ obj->ref = 1;
obj->pContainedObjects = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(struct list)); obj->pContainedObjects = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(struct list));
list_init (obj->pContainedObjects); list_init (obj->pContainedObjects);
lock_module(); lock_module();
return IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface ((LPDIRECTMUSICCONTAINER)&obj->ContainerVtbl, lpcGUID, ppobj); hr = IDirectMusicContainer_QueryInterface(&obj->IDirectMusicContainer_iface, lpcGUID, ppobj);
IDirectMusicContainer_Release(&obj->IDirectMusicContainer_iface);
return hr;
} }
...@@ -56,7 +56,6 @@ typedef struct IDirectMusicLoaderCF IDirectMusicLoaderCF; ...@@ -56,7 +56,6 @@ typedef struct IDirectMusicLoaderCF IDirectMusicLoaderCF;
typedef struct IDirectMusicContainerCF IDirectMusicContainerCF; typedef struct IDirectMusicContainerCF IDirectMusicContainerCF;
typedef struct IDirectMusicLoaderImpl IDirectMusicLoaderImpl; typedef struct IDirectMusicLoaderImpl IDirectMusicLoaderImpl;
typedef struct IDirectMusicContainerImpl IDirectMusicContainerImpl;
typedef struct IDirectMusicLoaderFileStream IDirectMusicLoaderFileStream; typedef struct IDirectMusicLoaderFileStream IDirectMusicLoaderFileStream;
typedef struct IDirectMusicLoaderResourceStream IDirectMusicLoaderResourceStream; typedef struct IDirectMusicLoaderResourceStream IDirectMusicLoaderResourceStream;
...@@ -110,26 +109,6 @@ typedef struct _WINE_CONTAINER_ENTRY { ...@@ -110,26 +109,6 @@ typedef struct _WINE_CONTAINER_ENTRY {
} WINE_CONTAINER_ENTRY, *LPWINE_CONTAINER_ENTRY; } WINE_CONTAINER_ENTRY, *LPWINE_CONTAINER_ENTRY;
/***************************************************************************** /*****************************************************************************
* IDirectMusicContainerImpl implementation structure
*/
struct IDirectMusicContainerImpl {
/* VTABLEs */
const IDirectMusicContainerVtbl *ContainerVtbl;
const IDirectMusicObjectVtbl *ObjectVtbl;
const IPersistStreamVtbl *PersistStreamVtbl;
/* reference counter */
LONG dwRef;
/* stream */
LPSTREAM pStream;
/* header */
DMUS_IO_CONTAINER_HEADER Header;
/* data */
struct list *pContainedObjects;
/* descriptor */
DMUS_OBJECTDESC Desc;
};
/*****************************************************************************
* IDirectMusicLoaderFileStream implementation structure * IDirectMusicLoaderFileStream implementation structure
*/ */
struct IDirectMusicLoaderFileStream { struct IDirectMusicLoaderFileStream {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment