Commit 98a36f46 authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

dmloader: Merge and simplify the IClassFactory implementations.

parent cf4aec0c
......@@ -2,7 +2,6 @@ MODULE = dmloader.dll
IMPORTS = dxguid uuid ole32 advapi32
C_SRCS = \
classfactory.c \
container.c \
debug.c \
dmloader_main.c \
......
/* IDirectMusicLoaderCF
* IDirectMusicContainerCF
*
* Copyright (C) 2004 Rok Mandeljc
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "dmloader_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
/*****************************************************************************
* IDirectMusicLoaderCF implementation
*/
static ULONG WINAPI IDirectMusicLoaderCF_AddRef (LPCLASSFACTORY iface);
static HRESULT WINAPI IDirectMusicLoaderCF_QueryInterface (LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj) {
IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
if (IsEqualIID (riid, &IID_IUnknown) ||
IsEqualIID (riid, &IID_IClassFactory)) {
IDirectMusicLoaderCF_AddRef (iface);
*ppobj = This;
return S_OK;
}
WARN(": not found\n");
return E_NOINTERFACE;
}
static ULONG WINAPI IDirectMusicLoaderCF_AddRef (LPCLASSFACTORY iface) {
IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
TRACE("(%p): AddRef from %d\n", This, This->dwRef);
return InterlockedIncrement (&This->dwRef);
}
static ULONG WINAPI IDirectMusicLoaderCF_Release (LPCLASSFACTORY iface) {
IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
DWORD dwRef = InterlockedDecrement (&This->dwRef);
TRACE("(%p): ReleaseRef to %d\n", This, dwRef);
if (dwRef == 0) {
HeapFree(GetProcessHeap (), 0, This);
/* decrease number of instances */
InterlockedDecrement(&dwDirectMusicLoader);
}
return dwRef;
}
static HRESULT WINAPI IDirectMusicLoaderCF_CreateInstance (LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
if (pOuter) {
ERR(": pOuter should be NULL\n");
return CLASS_E_NOAGGREGATION;
}
return DMUSIC_CreateDirectMusicLoaderImpl (riid, ppobj, pOuter);
}
static HRESULT WINAPI IDirectMusicLoaderCF_LockServer (LPCLASSFACTORY iface, BOOL dolock) {
IDirectMusicLoaderCF *This = (IDirectMusicLoaderCF *)iface;
TRACE("(%p, %d)\n", This, dolock);
if (dolock)
InterlockedIncrement (&dwDirectMusicLoader);
else
InterlockedDecrement (&dwDirectMusicLoader);
return S_OK;
}
static const IClassFactoryVtbl DirectMusicLoaderCF_Vtbl = {
IDirectMusicLoaderCF_QueryInterface,
IDirectMusicLoaderCF_AddRef,
IDirectMusicLoaderCF_Release,
IDirectMusicLoaderCF_CreateInstance,
IDirectMusicLoaderCF_LockServer
};
HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
IDirectMusicLoaderCF *obj;
TRACE("(%s, %p, %p)\n", debugstr_dmguid(lpcGUID), ppobj, pUnkOuter);
obj = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicLoaderCF));
if (NULL == obj) {
*ppobj = NULL;
return E_OUTOFMEMORY;
}
obj->lpVtbl = &DirectMusicLoaderCF_Vtbl;
obj->dwRef = 0; /* will be inited with QueryInterface */
/* increase number of instances */
InterlockedIncrement (&dwDirectMusicLoader);
return IDirectMusicLoaderCF_QueryInterface ((LPCLASSFACTORY)obj, lpcGUID, ppobj);
}
/*****************************************************************************
* IDirectMusicContainerCF implementation
*/
static ULONG WINAPI IDirectMusicContainerCF_AddRef (LPCLASSFACTORY iface);
static HRESULT WINAPI IDirectMusicContainerCF_QueryInterface (LPCLASSFACTORY iface, REFIID riid, LPVOID *ppobj) {
IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
if (IsEqualIID (riid, &IID_IUnknown) ||
IsEqualIID (riid, &IID_IClassFactory)) {
IDirectMusicContainerCF_AddRef (iface);
*ppobj = This;
return S_OK;
}
WARN(": not found\n");
return E_NOINTERFACE;
}
static ULONG WINAPI IDirectMusicContainerCF_AddRef (LPCLASSFACTORY iface) {
IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
TRACE("(%p): AddRef from %d\n", This, This->dwRef);
return InterlockedIncrement (&This->dwRef);
}
static ULONG WINAPI IDirectMusicContainerCF_Release (LPCLASSFACTORY iface) {
IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
DWORD dwRef = InterlockedDecrement (&This->dwRef);
TRACE("(%p): ReleaseRef to %d\n", This, dwRef);
if (dwRef == 0) {
HeapFree(GetProcessHeap (), 0, This);
/* decrease number of instances */
InterlockedDecrement(&dwDirectMusicContainer);
}
return dwRef;
}
static HRESULT WINAPI IDirectMusicContainerCF_CreateInstance (LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
if (pOuter) {
ERR(": pOuter should be NULL\n");
return CLASS_E_NOAGGREGATION;
}
return DMUSIC_CreateDirectMusicContainerImpl (riid, ppobj, pOuter);
}
static HRESULT WINAPI IDirectMusicContainerCF_LockServer (LPCLASSFACTORY iface, BOOL dolock) {
IDirectMusicContainerCF *This = (IDirectMusicContainerCF *)iface;
TRACE("(%p, %d)\n", This, dolock);
if (dolock)
InterlockedIncrement (&dwDirectMusicContainer);
else
InterlockedDecrement (&dwDirectMusicContainer);
return S_OK;
}
static const IClassFactoryVtbl DirectMusicContainerCF_Vtbl = {
IDirectMusicContainerCF_QueryInterface,
IDirectMusicContainerCF_AddRef,
IDirectMusicContainerCF_Release,
IDirectMusicContainerCF_CreateInstance,
IDirectMusicContainerCF_LockServer
};
HRESULT WINAPI DMUSIC_CreateDirectMusicContainerCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) {
IDirectMusicContainerCF *obj;
TRACE("(%s, %p, %p)\n", debugstr_dmguid(lpcGUID), ppobj, pUnkOuter);
obj = HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicContainerCF));
if (NULL == obj) {
*ppobj = NULL;
return E_OUTOFMEMORY;
}
obj->lpVtbl = &DirectMusicContainerCF_Vtbl;
obj->dwRef = 0; /* will be inited with QueryInterface */
/* increase number of instances */
InterlockedIncrement (&dwDirectMusicContainer);
return IDirectMusicContainerCF_QueryInterface ((LPCLASSFACTORY)obj, lpcGUID, ppobj);
}
......@@ -26,6 +26,87 @@ static HINSTANCE instance;
LONG dwDirectMusicContainer = 0;
LONG dwDirectMusicLoader = 0;
typedef struct {
IClassFactory IClassFactory_iface;
HRESULT WINAPI (*fnCreateInstance)(REFIID riid, void **ppv, IUnknown *pUnkOuter);
} IClassFactoryImpl;
/******************************************************************
* IClassFactory implementation
*/
static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
{
return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
}
static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{
if (ppv == NULL)
return E_POINTER;
if (IsEqualGUID(&IID_IUnknown, riid))
TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
else if (IsEqualGUID(&IID_IClassFactory, riid))
TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
else {
FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
*ppv = NULL;
return E_NOINTERFACE;
}
*ppv = iface;
IClassFactory_AddRef(iface);
return S_OK;
}
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{
InterlockedIncrement(&dwDirectMusicLoader);
return 2; /* non-heap based object */
}
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{
InterlockedDecrement(&dwDirectMusicLoader);
return 1; /* non-heap based object */
}
static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
REFIID riid, void **ppv)
{
IClassFactoryImpl *This = impl_from_IClassFactory(iface);
TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv);
return This->fnCreateInstance(riid, ppv, pUnkOuter);
}
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
{
TRACE("(%d)\n", dolock);
if (dolock)
InterlockedIncrement(&dwDirectMusicLoader);
else
InterlockedDecrement(&dwDirectMusicLoader);
return S_OK;
}
static const IClassFactoryVtbl classfactory_vtbl = {
ClassFactory_QueryInterface,
ClassFactory_AddRef,
ClassFactory_Release,
ClassFactory_CreateInstance,
ClassFactory_LockServer
};
static IClassFactoryImpl dm_loader_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicLoaderImpl};
static IClassFactoryImpl dm_container_CF = {{&classfactory_vtbl},
DMUSIC_CreateDirectMusicContainerImpl};
/******************************************************************
* DllMain
*/
......@@ -62,11 +143,15 @@ HRESULT WINAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
TRACE("(%s, %s, %p)\n", debugstr_dmguid(rclsid), debugstr_dmguid(riid), ppv);
if (IsEqualCLSID (rclsid, &CLSID_DirectMusicLoader) && IsEqualIID (riid, &IID_IClassFactory)) {
return DMUSIC_CreateDirectMusicLoaderCF (riid, ppv, NULL);
} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicContainer) && IsEqualIID (riid, &IID_IClassFactory)) {
return DMUSIC_CreateDirectMusicContainerCF (riid, ppv, NULL);
}
IClassFactory_AddRef(&dm_loader_CF.IClassFactory_iface);
*ppv = &dm_loader_CF.IClassFactory_iface;
return S_OK;
} else if (IsEqualCLSID (rclsid, &CLSID_DirectMusicContainer) && IsEqualIID (riid, &IID_IClassFactory)) {
IClassFactory_AddRef(&dm_container_CF.IClassFactory_iface);
*ppv = &dm_container_CF.IClassFactory_iface;
return S_OK;
}
WARN(": no class found\n");
return CLASS_E_CLASSNOTAVAILABLE;
}
......
......@@ -64,33 +64,12 @@ typedef struct IDirectMusicLoaderGenericStream IDirectMusicLoaderGenericStream;
/*****************************************************************************
* Creation helpers
*/
extern HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicContainerCF (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderImpl (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicContainerImpl (LPCGUID lpcGUID, LPVOID *ppobj, LPUNKNOWN pUnkOuter) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderFileStream (LPVOID *ppobj) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderResourceStream (LPVOID *ppobj) DECLSPEC_HIDDEN;
extern HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderGenericStream (LPVOID *ppobj) DECLSPEC_HIDDEN;
/*****************************************************************************
* IDirectMusicLoaderCF implementation structure
*/
struct IDirectMusicLoaderCF {
/* IUnknown fields */
const IClassFactoryVtbl *lpVtbl;
LONG dwRef;
};
/*****************************************************************************
* IDirectMusicContainerCF implementation structure
*/
struct IDirectMusicContainerCF {
/* IUnknown fields */
const IClassFactoryVtbl *lpVtbl;
LONG dwRef;
};
/* cache/alias entry */
typedef struct _WINE_LOADER_ENTRY {
struct list entry; /* for listing elements */
......
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