From bf4481d3f0692f44a9bf9dd0b8e9af72a4b3521d Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Thu, 19 Jul 2012 02:00:27 +0200 Subject: [PATCH] dsound: Merge the DirectSound create functions. --- dlls/dsound/dsound.c | 92 ++++++++++---------------------------------- dlls/dsound/dsound_main.c | 4 +- dlls/dsound/dsound_private.h | 4 +- dlls/dsound/duplex.c | 2 +- 4 files changed, 25 insertions(+), 77 deletions(-) diff --git a/dlls/dsound/dsound.c b/dlls/dsound/dsound.c index 6ce01b28f5c..9060e7654fb 100644 --- a/dlls/dsound/dsound.c +++ b/dlls/dsound/dsound.c @@ -583,9 +583,12 @@ static HRESULT IDirectSound8_IDirectSound8_Create( return DS_OK; } -static HRESULT IDirectSoundImpl_Create(void **ppv, BOOL has_ds8) +static HRESULT IDirectSoundImpl_Create(REFIID riid, void **ppv, BOOL has_ds8) { IDirectSoundImpl *obj; + HRESULT hr; + + TRACE("(%s, %p)\n", debugstr_guid(riid), ppv); *ppv = NULL; obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj)); @@ -594,48 +597,28 @@ static HRESULT IDirectSoundImpl_Create(void **ppv, BOOL has_ds8) return DSERR_OUTOFMEMORY; } + setup_dsound_options(); + obj->IUnknown_iface.lpVtbl = &unk_vtbl; - obj->ref = 0; - obj->numIfaces = 0; + obj->ref = 1; + obj->numIfaces = 1; obj->device = NULL; obj->has_ds8 = has_ds8; - *ppv = obj; - return DS_OK; + hr = IUnknown_QueryInterface(&obj->IUnknown_iface, riid, ppv); + IUnknown_Release(&obj->IUnknown_iface); + + return hr; } -HRESULT DSOUND_Create( - REFIID riid, - LPDIRECTSOUND *ppDS) +HRESULT DSOUND_Create(REFIID riid, void **ppv) { - LPDIRECTSOUND8 pDS; - HRESULT hr; - TRACE("(%s, %p)\n", debugstr_guid(riid), ppDS); - - if (!IsEqualIID(riid, &IID_IUnknown) && - !IsEqualIID(riid, &IID_IDirectSound)) { - *ppDS = 0; - return E_NOINTERFACE; - } - - /* Get dsound configuration */ - setup_dsound_options(); - - hr = IDirectSoundImpl_Create((void **)&pDS, FALSE); - if (hr == DS_OK) { - hr = IDirectSound_IDirectSound_Create(pDS, ppDS); - if (*ppDS) - IDirectSound_IDirectSound_AddRef(*ppDS); - else { - WARN("IDirectSound_IDirectSound_Create failed\n"); - IDirectSound8_Release(pDS); - } - } else { - WARN("IDirectSoundImpl_Create failed\n"); - *ppDS = 0; - } + return IDirectSoundImpl_Create(riid, ppv, FALSE); +} - return hr; +HRESULT DSOUND_Create8(REFIID riid, void **ppv) +{ + return IDirectSoundImpl_Create(riid, ppv, TRUE); } /******************************************************************************* @@ -674,7 +657,7 @@ HRESULT WINAPI DirectSoundCreate( return DSERR_INVALIDPARAM; } - hr = DSOUND_Create(&IID_IDirectSound, &pDS); + hr = DSOUND_Create(&IID_IDirectSound, (void **)&pDS); if (hr == DS_OK) { hr = IDirectSound_Initialize(pDS, lpcGUID); if (hr != DS_OK) { @@ -691,41 +674,6 @@ HRESULT WINAPI DirectSoundCreate( return hr; } -HRESULT DSOUND_Create8( - REFIID riid, - LPDIRECTSOUND8 *ppDS) -{ - LPDIRECTSOUND8 pDS; - HRESULT hr; - TRACE("(%s, %p)\n", debugstr_guid(riid), ppDS); - - if (!IsEqualIID(riid, &IID_IUnknown) && - !IsEqualIID(riid, &IID_IDirectSound) && - !IsEqualIID(riid, &IID_IDirectSound8)) { - *ppDS = 0; - return E_NOINTERFACE; - } - - /* Get dsound configuration */ - setup_dsound_options(); - - hr = IDirectSoundImpl_Create((void **)&pDS, TRUE); - if (hr == DS_OK) { - hr = IDirectSound8_IDirectSound8_Create(pDS, ppDS); - if (*ppDS) - IDirectSound8_IDirectSound8_AddRef(*ppDS); - else { - WARN("IDirectSound8_IDirectSound8_Create failed\n"); - IDirectSound8_Release(pDS); - } - } else { - WARN("IDirectSoundImpl_Create failed\n"); - *ppDS = 0; - } - - return hr; -} - /******************************************************************************* * DirectSoundCreate8 (DSOUND.11) * @@ -762,7 +710,7 @@ HRESULT WINAPI DirectSoundCreate8( return DSERR_INVALIDPARAM; } - hr = DSOUND_Create8(&IID_IDirectSound8, &pDS); + hr = DSOUND_Create8(&IID_IDirectSound8, (void **)&pDS); if (hr == DS_OK) { hr = IDirectSound8_Initialize(pDS, lpcGUID); if (hr != DS_OK) { diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c index c0d2b33e902..e1969a16611 100644 --- a/dlls/dsound/dsound_main.c +++ b/dlls/dsound/dsound_main.c @@ -719,8 +719,8 @@ static const IClassFactoryVtbl DSCF_Vtbl = { }; static IClassFactoryImpl DSOUND_CF[] = { - { { &DSCF_Vtbl }, &CLSID_DirectSound, (FnCreateInstance)DSOUND_Create }, - { { &DSCF_Vtbl }, &CLSID_DirectSound8, (FnCreateInstance)DSOUND_Create8 }, + { { &DSCF_Vtbl }, &CLSID_DirectSound, DSOUND_Create }, + { { &DSCF_Vtbl }, &CLSID_DirectSound8, DSOUND_Create8 }, { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture, (FnCreateInstance)DSOUND_CaptureCreate }, { { &DSCF_Vtbl }, &CLSID_DirectSoundCapture8, (FnCreateInstance)DSOUND_CaptureCreate8 }, { { &DSCF_Vtbl }, &CLSID_DirectSoundFullDuplex, (FnCreateInstance)DSOUND_FullDuplexCreate }, diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index 8d361bc573f..d8227442b97 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -264,8 +264,8 @@ HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DEC /* dsound.c */ -HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS) DECLSPEC_HIDDEN; -HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS) DECLSPEC_HIDDEN; +HRESULT DSOUND_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN; +HRESULT DSOUND_Create8(REFIID riid, void **ppv) DECLSPEC_HIDDEN; /* primary.c */ diff --git a/dlls/dsound/duplex.c b/dlls/dsound/duplex.c index e3477ea016b..ccb0c9b077f 100644 --- a/dlls/dsound/duplex.c +++ b/dlls/dsound/duplex.c @@ -557,7 +557,7 @@ IDirectSoundFullDuplexImpl_Initialize( return DSERR_ALREADYINITIALIZED; } - hr = DSOUND_Create8(&IID_IDirectSound8, &This->renderer_device); + hr = DSOUND_Create8(&IID_IDirectSound8, (void **)&This->renderer_device); if (SUCCEEDED(hr)) hr = IDirectSound_Initialize(This->renderer_device, pRendererGuid); if (hr != DS_OK) { -- 2.11.4.GIT