Commit ec2a7a32 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dmsynth: Move constructor parameter checks to class factory.

parent 8ee23728
...@@ -27,7 +27,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dmsynth); ...@@ -27,7 +27,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
typedef struct { typedef struct {
IClassFactory IClassFactory_iface; IClassFactory IClassFactory_iface;
HRESULT (*fnCreateInstance)(REFIID riid, void **ppv); HRESULT (*create_instance)(IUnknown **ret_iface);
} IClassFactoryImpl; } IClassFactoryImpl;
/****************************************************************** /******************************************************************
...@@ -68,17 +68,24 @@ static ULONG WINAPI ClassFactory_Release(IClassFactory *iface) ...@@ -68,17 +68,24 @@ static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
return 1; /* non-heap based object */ return 1; /* non-heap based object */
} }
static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter, static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *unk_outer,
REFIID riid, void **ppv) REFIID riid, void **ret_iface)
{ {
IClassFactoryImpl *This = impl_from_IClassFactory(iface); IClassFactoryImpl *This = impl_from_IClassFactory(iface);
IUnknown *object;
HRESULT hr;
TRACE ("(%p, %s, %p)\n", pUnkOuter, debugstr_dmguid(riid), ppv); TRACE("(%p, %s, %p)\n", unk_outer, debugstr_dmguid(riid), ret_iface);
if (pUnkOuter) *ret_iface = NULL;
return CLASS_E_NOAGGREGATION; if (unk_outer) return CLASS_E_NOAGGREGATION;
if (SUCCEEDED(hr = This->create_instance(&object)))
{
hr = IUnknown_QueryInterface(object, riid, ret_iface);
IUnknown_Release(object);
}
return This->fnCreateInstance(riid, ppv); return hr;
} }
static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock) static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
...@@ -95,9 +102,8 @@ static const IClassFactoryVtbl classfactory_vtbl = { ...@@ -95,9 +102,8 @@ static const IClassFactoryVtbl classfactory_vtbl = {
ClassFactory_LockServer ClassFactory_LockServer
}; };
static IClassFactoryImpl Synth_CF = {{&classfactory_vtbl}, DMUSIC_CreateDirectMusicSynthImpl}; static IClassFactoryImpl Synth_CF = {{&classfactory_vtbl}, synth_create};
static IClassFactoryImpl SynthSink_CF = {{&classfactory_vtbl}, static IClassFactoryImpl SynthSink_CF = {{&classfactory_vtbl}, synth_sink_create};
DMUSIC_CreateDirectMusicSynthSinkImpl};
/****************************************************************** /******************************************************************
......
...@@ -43,8 +43,8 @@ ...@@ -43,8 +43,8 @@
/***************************************************************************** /*****************************************************************************
* ClassFactory * ClassFactory
*/ */
extern HRESULT DMUSIC_CreateDirectMusicSynthImpl(REFIID riid, void **ppobj); extern HRESULT synth_create(IUnknown **ret_iface);
extern HRESULT DMUSIC_CreateDirectMusicSynthSinkImpl(REFIID riid, void **ppobj); extern HRESULT synth_sink_create(IUnknown **ret_iface);
/***************************************************************************** /*****************************************************************************
* Misc. * Misc.
......
...@@ -737,19 +737,18 @@ static const IKsControlVtbl synth_control_vtbl = ...@@ -737,19 +737,18 @@ static const IKsControlVtbl synth_control_vtbl =
synth_control_KsEvent, synth_control_KsEvent,
}; };
HRESULT DMUSIC_CreateDirectMusicSynthImpl(REFIID riid, void **ppobj) HRESULT synth_create(IUnknown **ret_iface)
{ {
struct synth *obj; struct synth *obj;
HRESULT hr;
TRACE("(%s, %p)\n", debugstr_guid(riid), ppobj); TRACE("(%p)\n", ret_iface);
*ppobj = NULL; *ret_iface = NULL;
if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY;
obj->IDirectMusicSynth8_iface.lpVtbl = &synth_vtbl; obj->IDirectMusicSynth8_iface.lpVtbl = &synth_vtbl;
obj->IKsControl_iface.lpVtbl = &synth_control_vtbl; obj->IKsControl_iface.lpVtbl = &synth_control_vtbl;
obj->ref = 1; obj->ref = 1;
/* fill in caps */
obj->caps.dwSize = sizeof(DMUS_PORTCAPS); obj->caps.dwSize = sizeof(DMUS_PORTCAPS);
obj->caps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE; obj->caps.dwFlags = DMUS_PC_DLS | DMUS_PC_SOFTWARESYNTH | DMUS_PC_DIRECTSOUND | DMUS_PC_DLS2 | DMUS_PC_AUDIOPATH | DMUS_PC_WAVE;
obj->caps.guidPort = CLSID_DirectMusicSynth; obj->caps.guidPort = CLSID_DirectMusicSynth;
...@@ -762,8 +761,7 @@ HRESULT DMUSIC_CreateDirectMusicSynthImpl(REFIID riid, void **ppobj) ...@@ -762,8 +761,7 @@ HRESULT DMUSIC_CreateDirectMusicSynthImpl(REFIID riid, void **ppobj)
obj->caps.dwEffectFlags = DMUS_EFFECT_REVERB; obj->caps.dwEffectFlags = DMUS_EFFECT_REVERB;
lstrcpyW(obj->caps.wszDescription, L"Microsoft Synthesizer"); lstrcpyW(obj->caps.wszDescription, L"Microsoft Synthesizer");
hr = IDirectMusicSynth8_QueryInterface(&obj->IDirectMusicSynth8_iface, riid, ppobj); TRACE("Created DirectMusicSynth %p\n", obj);
IDirectMusicSynth8_Release(&obj->IDirectMusicSynth8_iface); *ret_iface = (IUnknown *)&obj->IDirectMusicSynth8_iface;
return S_OK;
return hr;
} }
...@@ -371,29 +371,27 @@ static const IKsControlVtbl synth_sink_control = ...@@ -371,29 +371,27 @@ static const IKsControlVtbl synth_sink_control =
synth_sink_control_KsEvent, synth_sink_control_KsEvent,
}; };
HRESULT DMUSIC_CreateDirectMusicSynthSinkImpl(REFIID riid, void **ret_iface) HRESULT synth_sink_create(IUnknown **ret_iface)
{ {
struct synth_sink *obj; struct synth_sink *obj;
HRESULT hr; HRESULT hr;
TRACE("(%s, %p)\n", debugstr_guid(riid), ret_iface); TRACE("(%p)\n", ret_iface);
*ret_iface = NULL; *ret_iface = NULL;
if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY; if (!(obj = calloc(1, sizeof(*obj)))) return E_OUTOFMEMORY;
obj->IDirectMusicSynthSink_iface.lpVtbl = &synth_sink_vtbl; obj->IDirectMusicSynthSink_iface.lpVtbl = &synth_sink_vtbl;
obj->IKsControl_iface.lpVtbl = &synth_sink_control; obj->IKsControl_iface.lpVtbl = &synth_sink_control;
obj->ref = 1; obj->ref = 1;
hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (LPVOID*)&obj->latency_clock); hr = CoCreateInstance(&CLSID_SystemClock, NULL, CLSCTX_INPROC_SERVER, &IID_IReferenceClock, (void **)&obj->latency_clock);
if (FAILED(hr)) if (FAILED(hr))
{ {
free(obj); free(obj);
return hr; return hr;
} }
hr = IDirectMusicSynthSink_QueryInterface(&obj->IDirectMusicSynthSink_iface, riid, ret_iface); TRACE("Created DirectMusicSynthSink %p\n", obj);
IDirectMusicSynthSink_Release(&obj->IDirectMusicSynthSink_iface); *ret_iface = (IUnknown *)&obj->IDirectMusicSynthSink_iface;
return S_OK;
return hr;
} }
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