From ce5fb9bb297b50e3810aba6d27eeb04678039fe5 Mon Sep 17 00:00:00 2001 From: Vitaliy Margolen Date: Fri, 22 Dec 2006 10:54:29 -0700 Subject: [PATCH] dinput: AddRef and Release parent DirectInput class. --- dlls/dinput/joystick_linux.c | 4 ++-- dlls/dinput/joystick_linuxinput.c | 4 ++++ dlls/dinput/keyboard.c | 10 +++++++++- dlls/dinput/mouse.c | 5 +++++ dlls/dinput/tests/keyboard.c | 2 ++ dlls/dinput/tests/mouse.c | 4 +++- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c index 745fd5cbaa8..914d05decaa 100644 --- a/dlls/dinput/joystick_linux.c +++ b/dlls/dinput/joystick_linux.c @@ -484,7 +484,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di hr = create_DataFormat(&c_dfDIJoystick2, &newDevice->base.data_format); if (hr != DI_OK) goto FAILED; - IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput); + IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput); newDevice->devcaps.dwSize = sizeof(newDevice->devcaps); newDevice->devcaps.dwFlags = DIDC_ATTACHED; @@ -613,8 +613,8 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface) release_DataFormat(&This->base.data_format); This->base.crit.DebugInfo->Spare[0] = 0; + IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput); DeleteCriticalSection(&This->base.crit); - IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A)This->dinput); HeapFree(GetProcessHeap(),0,This); return 0; diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c index 4cce22219b7..b0497309bb3 100644 --- a/dlls/dinput/joystick_linuxinput.c +++ b/dlls/dinput/joystick_linuxinput.c @@ -393,7 +393,10 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm /* create the default transform filter */ if (create_DataFormat(&c_dfDIJoystick2, &newDevice->base.data_format) == DI_OK) + { + IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput); return newDevice; + } HeapFree(GetProcessHeap(),0,newDevice); return NULL; @@ -491,6 +494,7 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface) /* release the data transform filter */ release_DataFormat(&This->base.data_format); + IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput); DeleteCriticalSection(&This->base.crit); HeapFree(GetProcessHeap(),0,This); diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 14562b44971..4308b45c1db 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -198,7 +198,12 @@ static SysKeyboardImpl *alloc_device(REFGUID rguid, const void *kvt, IDirectInpu newDevice->base.data_format.wine_df = &c_dfDIKeyboard; if (create_DataFormat(&c_dfDIKeyboard, &newDevice->base.data_format) == DI_OK) + { + IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput); return newDevice; + } + + HeapFree(GetProcessHeap(), 0, newDevice); return NULL; } @@ -214,6 +219,7 @@ static HRESULT keyboarddev_create_deviceA(IDirectInputImpl *dinput, REFGUID rgui IsEqualGUID(&IID_IDirectInputDevice8A,riid)) { *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysKeyboardAvt, dinput); TRACE("Creating a Keyboard device (%p)\n", *pdev); + if (!*pdev) return DIERR_OUTOFMEMORY; return DI_OK; } else return DIERR_NOINTERFACE; @@ -232,6 +238,7 @@ static HRESULT keyboarddev_create_deviceW(IDirectInputImpl *dinput, REFGUID rgui IsEqualGUID(&IID_IDirectInputDevice8W,riid)) { *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysKeyboardWvt, dinput); TRACE("Creating a Keyboard device (%p)\n", *pdev); + if (!*pdev) return DIERR_OUTOFMEMORY; return DI_OK; } else return DIERR_NOINTERFACE; @@ -257,8 +264,9 @@ static ULONG WINAPI SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface) set_dinput_hook(WH_KEYBOARD_LL, NULL); - DeleteCriticalSection(&This->base.crit); HeapFree(GetProcessHeap(), 0, This->base.data_queue); + IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput); + DeleteCriticalSection(&This->base.crit); HeapFree(GetProcessHeap(), 0, This); return DI_OK; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 9ab1b1f906e..7b4fef6a5e7 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -194,8 +194,12 @@ static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputIm newDevice->base.data_format.wine_df = &c_dfDIMouse2; if (create_DataFormat(&c_dfDIMouse2, &newDevice->base.data_format) == DI_OK) + { + IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput); return newDevice; + } + HeapFree(GetProcessHeap(), 0, newDevice); return NULL; } @@ -270,6 +274,7 @@ static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface) release_DataFormat(&This->base.data_format); + IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput); DeleteCriticalSection(&This->base.crit); HeapFree(GetProcessHeap(),0,This); return 0; diff --git a/dlls/dinput/tests/keyboard.c b/dlls/dinput/tests/keyboard.c index c911dcb6d00..4503f2ffe3e 100644 --- a/dlls/dinput/tests/keyboard.c +++ b/dlls/dinput/tests/keyboard.c @@ -94,6 +94,8 @@ static void acquire_tests(LPDIRECTINPUT pDI, HWND hwnd) ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr)); hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state); ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr)); + + if (pKeyboard) IUnknown_Release(pKeyboard); } static const HRESULT SetCoop_null_window[16] = { diff --git a/dlls/dinput/tests/mouse.c b/dlls/dinput/tests/mouse.c index 0743a2e8912..db95ab26a3e 100644 --- a/dlls/dinput/tests/mouse.c +++ b/dlls/dinput/tests/mouse.c @@ -95,6 +95,7 @@ static void mouse_tests(void) LPDIRECTINPUT pDI = NULL; HINSTANCE hInstance = GetModuleHandle(NULL); HWND hwnd; + ULONG ref = 0; hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &pDI, NULL); ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr)); @@ -112,7 +113,8 @@ static void mouse_tests(void) DestroyWindow(hwnd); } - if (pDI) IUnknown_Release(pDI); + if (pDI) ref = IUnknown_Release(pDI); + ok(!ref, "IDirectInput_Release() reference count = %d\n", ref); } START_TEST(mouse)