Commit ce5fb9bb authored by Vitaliy Margolen's avatar Vitaliy Margolen Committed by Alexandre Julliard

dinput: AddRef and Release parent DirectInput class.

parent 0ee7db45
...@@ -484,7 +484,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di ...@@ -484,7 +484,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
hr = create_DataFormat(&c_dfDIJoystick2, &newDevice->base.data_format); hr = create_DataFormat(&c_dfDIJoystick2, &newDevice->base.data_format);
if (hr != DI_OK) goto FAILED; if (hr != DI_OK) goto FAILED;
IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput); IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
newDevice->devcaps.dwSize = sizeof(newDevice->devcaps); newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
newDevice->devcaps.dwFlags = DIDC_ATTACHED; newDevice->devcaps.dwFlags = DIDC_ATTACHED;
...@@ -613,8 +613,8 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface) ...@@ -613,8 +613,8 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
release_DataFormat(&This->base.data_format); release_DataFormat(&This->base.data_format);
This->base.crit.DebugInfo->Spare[0] = 0; This->base.crit.DebugInfo->Spare[0] = 0;
IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
DeleteCriticalSection(&This->base.crit); DeleteCriticalSection(&This->base.crit);
IDirectInputDevice_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
HeapFree(GetProcessHeap(),0,This); HeapFree(GetProcessHeap(),0,This);
return 0; return 0;
......
...@@ -393,7 +393,10 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm ...@@ -393,7 +393,10 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm
/* create the default transform filter */ /* create the default transform filter */
if (create_DataFormat(&c_dfDIJoystick2, &newDevice->base.data_format) == DI_OK) if (create_DataFormat(&c_dfDIJoystick2, &newDevice->base.data_format) == DI_OK)
{
IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
return newDevice; return newDevice;
}
HeapFree(GetProcessHeap(),0,newDevice); HeapFree(GetProcessHeap(),0,newDevice);
return NULL; return NULL;
...@@ -491,6 +494,7 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface) ...@@ -491,6 +494,7 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
/* release the data transform filter */ /* release the data transform filter */
release_DataFormat(&This->base.data_format); release_DataFormat(&This->base.data_format);
IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
DeleteCriticalSection(&This->base.crit); DeleteCriticalSection(&This->base.crit);
HeapFree(GetProcessHeap(),0,This); HeapFree(GetProcessHeap(),0,This);
......
...@@ -198,7 +198,12 @@ static SysKeyboardImpl *alloc_device(REFGUID rguid, const void *kvt, IDirectInpu ...@@ -198,7 +198,12 @@ static SysKeyboardImpl *alloc_device(REFGUID rguid, const void *kvt, IDirectInpu
newDevice->base.data_format.wine_df = &c_dfDIKeyboard; newDevice->base.data_format.wine_df = &c_dfDIKeyboard;
if (create_DataFormat(&c_dfDIKeyboard, &newDevice->base.data_format) == DI_OK) if (create_DataFormat(&c_dfDIKeyboard, &newDevice->base.data_format) == DI_OK)
{
IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
return newDevice; return newDevice;
}
HeapFree(GetProcessHeap(), 0, newDevice);
return NULL; return NULL;
} }
...@@ -214,6 +219,7 @@ static HRESULT keyboarddev_create_deviceA(IDirectInputImpl *dinput, REFGUID rgui ...@@ -214,6 +219,7 @@ static HRESULT keyboarddev_create_deviceA(IDirectInputImpl *dinput, REFGUID rgui
IsEqualGUID(&IID_IDirectInputDevice8A,riid)) { IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
*pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysKeyboardAvt, dinput); *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysKeyboardAvt, dinput);
TRACE("Creating a Keyboard device (%p)\n", *pdev); TRACE("Creating a Keyboard device (%p)\n", *pdev);
if (!*pdev) return DIERR_OUTOFMEMORY;
return DI_OK; return DI_OK;
} else } else
return DIERR_NOINTERFACE; return DIERR_NOINTERFACE;
...@@ -232,6 +238,7 @@ static HRESULT keyboarddev_create_deviceW(IDirectInputImpl *dinput, REFGUID rgui ...@@ -232,6 +238,7 @@ static HRESULT keyboarddev_create_deviceW(IDirectInputImpl *dinput, REFGUID rgui
IsEqualGUID(&IID_IDirectInputDevice8W,riid)) { IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
*pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysKeyboardWvt, dinput); *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysKeyboardWvt, dinput);
TRACE("Creating a Keyboard device (%p)\n", *pdev); TRACE("Creating a Keyboard device (%p)\n", *pdev);
if (!*pdev) return DIERR_OUTOFMEMORY;
return DI_OK; return DI_OK;
} else } else
return DIERR_NOINTERFACE; return DIERR_NOINTERFACE;
...@@ -257,8 +264,9 @@ static ULONG WINAPI SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface) ...@@ -257,8 +264,9 @@ static ULONG WINAPI SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
set_dinput_hook(WH_KEYBOARD_LL, NULL); set_dinput_hook(WH_KEYBOARD_LL, NULL);
DeleteCriticalSection(&This->base.crit);
HeapFree(GetProcessHeap(), 0, This->base.data_queue); HeapFree(GetProcessHeap(), 0, This->base.data_queue);
IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
DeleteCriticalSection(&This->base.crit);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
return DI_OK; return DI_OK;
......
...@@ -194,8 +194,12 @@ static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputIm ...@@ -194,8 +194,12 @@ static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputIm
newDevice->base.data_format.wine_df = &c_dfDIMouse2; newDevice->base.data_format.wine_df = &c_dfDIMouse2;
if (create_DataFormat(&c_dfDIMouse2, &newDevice->base.data_format) == DI_OK) if (create_DataFormat(&c_dfDIMouse2, &newDevice->base.data_format) == DI_OK)
{
IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
return newDevice; return newDevice;
}
HeapFree(GetProcessHeap(), 0, newDevice);
return NULL; return NULL;
} }
...@@ -270,6 +274,7 @@ static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface) ...@@ -270,6 +274,7 @@ static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
release_DataFormat(&This->base.data_format); release_DataFormat(&This->base.data_format);
IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
DeleteCriticalSection(&This->base.crit); DeleteCriticalSection(&This->base.crit);
HeapFree(GetProcessHeap(),0,This); HeapFree(GetProcessHeap(),0,This);
return 0; return 0;
......
...@@ -94,6 +94,8 @@ static void acquire_tests(LPDIRECTINPUT pDI, HWND hwnd) ...@@ -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)); ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state); hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr)); ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr));
if (pKeyboard) IUnknown_Release(pKeyboard);
} }
static const HRESULT SetCoop_null_window[16] = { static const HRESULT SetCoop_null_window[16] = {
......
...@@ -95,6 +95,7 @@ static void mouse_tests(void) ...@@ -95,6 +95,7 @@ static void mouse_tests(void)
LPDIRECTINPUT pDI = NULL; LPDIRECTINPUT pDI = NULL;
HINSTANCE hInstance = GetModuleHandle(NULL); HINSTANCE hInstance = GetModuleHandle(NULL);
HWND hwnd; HWND hwnd;
ULONG ref = 0;
hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &pDI, NULL); hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr)); ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
...@@ -112,7 +113,8 @@ static void mouse_tests(void) ...@@ -112,7 +113,8 @@ static void mouse_tests(void)
DestroyWindow(hwnd); 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) START_TEST(mouse)
......
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