diff --git a/dlls/dmime/tests/performance.c b/dlls/dmime/tests/performance.c index 0932cd98d72..730ec523238 100644 --- a/dlls/dmime/tests/performance.c +++ b/dlls/dmime/tests/performance.c @@ -169,11 +169,11 @@ static HRESULT test_InitAudio(void) IDirectMusic_SetDirectSound(dmusic, dsound, NULL); ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); ref = get_refcount(dsound); - todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + ok(ref == 2, "dsound ref count got %d expected 2\n", ref); hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, NULL, NULL, 0, 64, 0, NULL); ok(hr == S_OK, "InitAudio failed: %08x\n", hr); ref = get_refcount(dsound); - todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + ok(ref == 2, "dsound ref count got %d expected 2\n", ref); ref = get_refcount(dmusic); ok(ref == 2, "dmusic ref count got %d expected 2\n", ref); destroy_performance(performance, dmusic, dsound); @@ -183,11 +183,11 @@ static HRESULT test_InitAudio(void) IDirectMusic_SetDirectSound(dmusic, dsound, NULL); ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); ref = get_refcount(dsound); - todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + ok(ref == 2, "dsound ref count got %d expected 2\n", ref); hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL); ok(hr == S_OK, "InitAudio failed: %08x\n", hr); ref = get_refcount(dsound); - todo_wine ok(ref == 3, "dsound ref count got %d expected 3\n", ref); + ok(ref == 3, "dsound ref count got %d expected 3\n", ref); ref = get_refcount(dmusic); ok(ref == 2, "dmusic ref count got %d expected 2\n", ref); destroy_performance(performance, dmusic, dsound); diff --git a/dlls/dmusic/Makefile.in b/dlls/dmusic/Makefile.in index 98cfaeff69f..a8955a2ab42 100644 --- a/dlls/dmusic/Makefile.in +++ b/dlls/dmusic/Makefile.in @@ -1,5 +1,5 @@ MODULE = dmusic.dll -IMPORTS = dxguid uuid ole32 advapi32 winmm +IMPORTS = dxguid uuid ole32 advapi32 dsound user32 winmm C_SRCS = \ buffer.c \ diff --git a/dlls/dmusic/dmusic.c b/dlls/dmusic/dmusic.c index b1c0a195d99..5dcda6455a1 100644 --- a/dlls/dmusic/dmusic.c +++ b/dlls/dmusic/dmusic.c @@ -73,6 +73,8 @@ static ULONG WINAPI IDirectMusic8Impl_Release(LPDIRECTMUSIC8 iface) if (!ref) { IReferenceClock_Release(&This->master_clock->IReferenceClock_iface); + if (This->dsound) + IDirectSound_Release(This->dsound); HeapFree(GetProcessHeap(), 0, This->system_ports); HeapFree(GetProcessHeap(), 0, This->ports); HeapFree(GetProcessHeap(), 0, This); @@ -271,11 +273,38 @@ static HRESULT WINAPI IDirectMusic8Impl_GetDefaultPort(LPDIRECTMUSIC8 iface, LPG return S_OK; } -static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound(LPDIRECTMUSIC8 iface, LPDIRECTSOUND dsound, HWND wnd) +static HRESULT WINAPI IDirectMusic8Impl_SetDirectSound(IDirectMusic8 *iface, IDirectSound *dsound, + HWND hwnd) { IDirectMusic8Impl *This = impl_from_IDirectMusic8(iface); + HRESULT hr; + int i; - FIXME("(%p)->(%p, %p): stub\n", This, dsound, wnd); + TRACE("(%p)->(%p, %p)\n", This, dsound, hwnd); + + for (i = 0; i < This->num_ports; i++) + { + hr = IDirectMusicPort_SetDirectSound(This->ports[i], NULL, NULL); + if (FAILED(hr)) + return hr; + } + + if (This->dsound) + IDirectSound_Release(This->dsound); + + if (!dsound) { + hr = DirectSoundCreate8(NULL, (IDirectSound8 **)&This->dsound, NULL); + if (FAILED(hr)) + return hr; + hr = IDirectSound_SetCooperativeLevel(This->dsound, hwnd ? hwnd : GetForegroundWindow(), + DSSCL_PRIORITY); + if (FAILED(hr)) + IDirectSound_Release(This->dsound); + return hr; + } + + IDirectSound_AddRef(dsound); + This->dsound = dsound; return S_OK; } diff --git a/dlls/dmusic/dmusic_private.h b/dlls/dmusic/dmusic_private.h index 08196873579..a470989fb5f 100644 --- a/dlls/dmusic/dmusic_private.h +++ b/dlls/dmusic/dmusic_private.h @@ -108,6 +108,7 @@ extern HRESULT DMUSIC_CreateDirectMusicInstrumentImpl (LPCGUID lpcGUID, LPVOID* struct IDirectMusic8Impl { IDirectMusic8 IDirectMusic8_iface; LONG ref; + IDirectSound *dsound; IReferenceClockImpl *master_clock; IDirectMusicPort **ports; int num_ports; diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c index 1d1f9488b9a..f701b2b9333 100644 --- a/dlls/dmusic/tests/dmusic.c +++ b/dlls/dmusic/tests/dmusic.c @@ -171,11 +171,11 @@ static void test_setdsound(void) hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL); ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); ref = get_refcount(dsound); - todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + ok(ref == 2, "dsound ref count got %d expected 2\n", ref); hr = IDirectMusic_CreatePort(dmusic, &GUID_NULL, ¶ms, &port, NULL); ok(hr == S_OK, "CreatePort returned: %x\n", hr); ref = get_refcount(dsound); - todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + ok(ref == 2, "dsound ref count got %d expected 2\n", ref); hr = IDirectMusicPort_Activate(port, TRUE); ok(hr == S_OK, "Port Activate returned: %x\n", hr); ref = get_refcount(dsound); @@ -197,11 +197,11 @@ static void test_setdsound(void) hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL); ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); ref = get_refcount(dsound); - todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + ok(ref == 2, "dsound ref count got %d expected 2\n", ref); hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL); ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); ref = get_refcount(dsound); - todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); + ok(ref == 2, "dsound ref count got %d expected 2\n", ref); /* Replacing one dsound with another */ hr = DirectSoundCreate8(NULL, (IDirectSound8 **)&dsound2, NULL); @@ -211,7 +211,7 @@ static void test_setdsound(void) ref = get_refcount(dsound); ok(ref == 1, "dsound ref count got %d expected 1\n", ref); ref = get_refcount(dsound2); - todo_wine ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref); + ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref); /* Replacing the dsound in the port */ hr = IDirectMusicPort_SetDirectSound(port, dsound, NULL); @@ -219,27 +219,27 @@ static void test_setdsound(void) ref = get_refcount(dsound); todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref); ref = get_refcount(dsound2); - todo_wine ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref); + ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref); /* Setting the dsound again on the port will mess with the parent dmusic */ hr = IDirectMusicPort_SetDirectSound(port, dsound, NULL); ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr); ref = get_refcount(dsound); todo_wine ok(ref == 3, "dsound ref count got %d expected 3\n", ref); ref = get_refcount(dsound2); - ok(ref == 1, "dsound2 ref count got %d expected 1\n", ref); + todo_wine ok(ref == 1, "dsound2 ref count got %d expected 1\n", ref); IDirectSound_AddRef(dsound2); /* Crash prevention */ hr = IDirectMusicPort_Activate(port, TRUE); ok(hr == S_OK, "Activate returned: %x\n", hr); ref = get_refcount(dsound); todo_wine ok(ref == 4, "dsound ref count got %d expected 4\n", ref); ref = get_refcount(dsound2); - ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref); + todo_wine ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref); hr = IDirectMusicPort_Activate(port, TRUE); todo_wine ok(hr == S_FALSE, "Activate returned: %x\n", hr); ref = get_refcount(dsound); todo_wine ok(ref == 4, "dsound ref count got %d expected 4\n", ref); ref = get_refcount(dsound2); - ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref); + todo_wine ok(ref == 2, "dsound2 ref count got %d expected 2\n", ref); /* Deactivating the port messes with the dsound refcount in the parent dmusic */ hr = IDirectMusicPort_Activate(port, FALSE);