dinput: AddRef and Release parent DirectInput class.

This commit is contained in:
Vitaliy Margolen 2006-12-22 10:54:29 -07:00 committed by Alexandre Julliard
parent 0ee7db45fd
commit ce5fb9bb29
6 changed files with 25 additions and 4 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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] = {

View file

@ -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)