From 6b30480021862ea7bb6475b21b3d709f80a9f9e2 Mon Sep 17 00:00:00 2001 From: Vitaliy Margolen Date: Sun, 9 Jan 2011 15:44:19 -0700 Subject: [PATCH] dinput: COM cleanup - use interfaces instead of vtbl. Combine both Unicode and ASCII interfaces into the same classes. --- dlls/dinput/device.c | 8 +++---- dlls/dinput/device_private.h | 3 ++- dlls/dinput/dinput_main.c | 23 ++++++++++++++----- dlls/dinput/joystick.c | 8 +++---- dlls/dinput/joystick_linux.c | 33 ++++++++++++++++++--------- dlls/dinput/joystick_linuxinput.c | 30 +++++++++++++++---------- dlls/dinput/joystick_osx.c | 29 ++++++++++++++++-------- dlls/dinput/keyboard.c | 31 +++++++++++++++++--------- dlls/dinput/mouse.c | 37 +++++++++++++++++++++---------- 9 files changed, 134 insertions(+), 68 deletions(-) diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index cc2ba7b0435..c54a756383f 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -43,20 +43,20 @@ WINE_DEFAULT_DEBUG_CHANNEL(dinput); static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface) { - return (IDirectInputDeviceImpl *) iface; + return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface); } static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) { - return (IDirectInputDeviceImpl *) iface; + return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface); } static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(IDirectInputDeviceImpl *This) { - return (IDirectInputDevice8A *)This; + return &This->IDirectInputDevice8A_iface; } static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(IDirectInputDeviceImpl *This) { - return (IDirectInputDevice8W *)This; + return &This->IDirectInputDevice8W_iface; } /****************************************************************************** diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 89862652a39..2461bec65a8 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -51,7 +51,8 @@ typedef struct typedef struct IDirectInputDeviceImpl IDirectInputDeviceImpl; struct IDirectInputDeviceImpl { - const void *lpVtbl; + IDirectInputDevice8A IDirectInputDevice8A_iface; + IDirectInputDevice8W IDirectInputDevice8W_iface; LONG ref; GUID guid; CRITICAL_SECTION crit; diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 14f7ca85ace..4eb52b36fb7 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -76,6 +76,15 @@ static inline IDirectInputImpl *impl_from_IDirectInput8W( IDirectInput8W *iface return CONTAINING_RECORD( iface, IDirectInputImpl, IDirectInput8W_iface ); } +static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface) +{ + return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface); +} +static inline IDirectInputDeviceImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) +{ + return CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface); +} + static const struct dinput_device *dinput_devices[] = { &mouse_device, @@ -498,8 +507,10 @@ static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, R if (!dinput_devices[i]->create_deviceA) continue; if ((ret = dinput_devices[i]->create_deviceA(This, rguid, riid, (LPDIRECTINPUTDEVICEA*) pvOut)) == DI_OK) { + IDirectInputDeviceImpl *dev = impl_from_IDirectInputDevice8A(*pvOut); + EnterCriticalSection( &This->crit ); - list_add_tail( &This->devices_list, &(*(IDirectInputDeviceImpl**)pvOut)->entry ); + list_add_tail( &This->devices_list, &dev->entry ); LeaveCriticalSection( &This->crit ); return DI_OK; } @@ -534,8 +545,10 @@ static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, R if (!dinput_devices[i]->create_deviceW) continue; if ((ret = dinput_devices[i]->create_deviceW(This, rguid, riid, (LPDIRECTINPUTDEVICEW*) pvOut)) == DI_OK) { + IDirectInputDeviceImpl *dev = impl_from_IDirectInputDevice8W(*pvOut); + EnterCriticalSection( &This->crit ); - list_add_tail( &This->devices_list, &(*(IDirectInputDeviceImpl**)pvOut)->entry ); + list_add_tail( &This->devices_list, &dev->entry ); LeaveCriticalSection( &This->crit ); return DI_OK; } @@ -922,7 +935,7 @@ static LRESULT CALLBACK LL_hook_proc( int code, WPARAM wparam, LPARAM lparam ) if (dev->acquired && dev->event_proc) { TRACE("calling %p->%p (%lx %lx)\n", dev, dev->event_proc, wparam, lparam); - skip |= dev->event_proc( (LPDIRECTINPUTDEVICE8A)dev, wparam, lparam ); + skip |= dev->event_proc( &dev->IDirectInputDevice8A_iface, wparam, lparam ); } LeaveCriticalSection( &dinput->crit ); } @@ -957,7 +970,7 @@ static LRESULT CALLBACK callwndproc_proc( int code, WPARAM wparam, LPARAM lparam if (msg->hwnd == dev->win && msg->hwnd != foreground) { TRACE( "%p window is not foreground - unacquiring %p\n", dev->win, dev ); - IDirectInputDevice_Unacquire( (LPDIRECTINPUTDEVICE8A)dev ); + IDirectInputDevice_Unacquire( &dev->IDirectInputDevice8A_iface ); } } LeaveCriticalSection( &dinput->crit ); @@ -1097,7 +1110,7 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface) { static HHOOK callwndproc_hook; static ULONG foreground_cnt; - IDirectInputDeviceImpl *dev = (IDirectInputDeviceImpl *)iface; + IDirectInputDeviceImpl *dev = impl_from_IDirectInputDevice8W(iface); EnterCriticalSection(&dinput_hook_crit); diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c index cce4ac5f161..1be6f313853 100644 --- a/dlls/dinput/joystick.c +++ b/dlls/dinput/joystick.c @@ -34,19 +34,19 @@ WINE_DEFAULT_DEBUG_CHANNEL(dinput); static inline JoystickGenericImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface) { - return (JoystickGenericImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface), JoystickGenericImpl, base); } static inline JoystickGenericImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) { - return (JoystickGenericImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), JoystickGenericImpl, base); } static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(JoystickGenericImpl *This) { - return (IDirectInputDevice8A *)This; + return &This->base.IDirectInputDevice8A_iface; } static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(JoystickGenericImpl *This) { - return (IDirectInputDevice8W *)This; + return &This->base.IDirectInputDevice8W_iface; } /****************************************************************************** diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c index a858ecd20f7..736b16c673e 100644 --- a/dlls/dinput/joystick_linux.c +++ b/dlls/dinput/joystick_linux.c @@ -101,19 +101,21 @@ struct JoystickImpl static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface) { - return (JoystickImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface), + JoystickGenericImpl, base), JoystickImpl, generic); } static inline JoystickImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) { - return (JoystickImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), + JoystickGenericImpl, base), JoystickImpl, generic); } static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(JoystickImpl *This) { - return (IDirectInputDevice8A *)This; + return &This->generic.base.IDirectInputDevice8A_iface; } static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(JoystickImpl *This) { - return (IDirectInputDevice8W *)This; + return &This->generic.base.IDirectInputDevice8W_iface; } static const GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */ @@ -296,8 +298,8 @@ static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTAN return FALSE; } -static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, - LPDIRECTINPUTDEVICEA* pdev, unsigned short index) +static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput, + JoystickImpl **pdev, unsigned short index) { DWORD i; JoystickImpl* newDevice; @@ -305,7 +307,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di LPDIDATAFORMAT df = NULL; int idx = 0; - TRACE("%s %p %p %p %hu\n", debugstr_guid(rguid), jvt, dinput, pdev, index); + TRACE("%s %p %p %hu\n", debugstr_guid(rguid), dinput, pdev, index); newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl)); if (newDevice == 0) { @@ -330,7 +332,8 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di newDevice->generic.devcaps.dwButtons = 128; } - newDevice->generic.base.lpVtbl = jvt; + newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt; + newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt; newDevice->generic.base.ref = 1; newDevice->generic.base.dinput = dinput; newDevice->generic.base.guid = *rguid; @@ -406,7 +409,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di _dump_DIDEVCAPS(&newDevice->generic.devcaps); } - *pdev = (LPDIRECTINPUTDEVICEA)newDevice; + *pdev = newDevice; return DI_OK; @@ -460,7 +463,11 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, RE IsEqualGUID(&IID_IDirectInputDevice7A, riid) || IsEqualGUID(&IID_IDirectInputDevice8A, riid)) { - return alloc_device(rguid, &JoystickAvt, dinput, pdev, index); + JoystickImpl *This; + HRESULT hr = alloc_device(rguid, dinput, &This, index); + + *pdev = (LPDIRECTINPUTDEVICEA)(This ? &This->generic.base.IDirectInputDevice8A_iface : NULL); + return hr; } WARN("no interface\n"); @@ -487,7 +494,11 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, RE IsEqualGUID(&IID_IDirectInputDevice7W, riid) || IsEqualGUID(&IID_IDirectInputDevice8W, riid)) { - return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev, index); + JoystickImpl *This; + HRESULT hr = alloc_device(rguid, dinput, &This, index); + + *pdev = (LPDIRECTINPUTDEVICEW)(This ? &This->generic.base.IDirectInputDevice8W_iface : NULL); + return hr; } WARN("no interface\n"); return DIERR_NOINTERFACE; diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c index 864ad695a62..3d8ee19657b 100644 --- a/dlls/dinput/joystick_linuxinput.c +++ b/dlls/dinput/joystick_linuxinput.c @@ -135,19 +135,21 @@ struct JoystickImpl static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface) { - return (JoystickImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface), + JoystickGenericImpl, base), JoystickImpl, generic); } static inline JoystickImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) { - return (JoystickImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), + JoystickGenericImpl, base), JoystickImpl, generic); } static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(JoystickImpl *This) { - return (IDirectInputDevice8A *) This; + return &This->generic.base.IDirectInputDevice8A_iface; } static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(JoystickImpl *This) { - return (IDirectInputDevice8W *) This; + return &This->generic.base.IDirectInputDevice8W_iface; } static void fake_current_js_state(JoystickImpl *ji); @@ -390,7 +392,7 @@ static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTAN return FALSE; } -static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, unsigned short index) +static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsigned short index) { JoystickImpl* newDevice; LPDIDATAFORMAT df = NULL; @@ -400,7 +402,8 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl)); if (!newDevice) return NULL; - newDevice->generic.base.lpVtbl = jvt; + newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt; + newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt; newDevice->generic.base.ref = 1; newDevice->generic.base.guid = *rguid; newDevice->generic.base.dinput = dinput; @@ -567,14 +570,16 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, RE IsEqualGUID(&IID_IDirectInputDevice7A, riid) || IsEqualGUID(&IID_IDirectInputDevice8A, riid)) { - *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, index); - TRACE("Created a Joystick device (%p)\n", *pdev); + JoystickImpl *This = alloc_device(rguid, dinput, index); + TRACE("Created a Joystick device (%p)\n", This); - if (*pdev == NULL) + if (!This) { ERR("out of memory\n"); + *pdev = NULL; return DIERR_OUTOFMEMORY; } + *pdev = (IDirectInputDeviceA*) &This->generic.base.IDirectInputDevice8A_iface; return DI_OK; } @@ -601,14 +606,15 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, RE IsEqualGUID(&IID_IDirectInputDevice7W, riid) || IsEqualGUID(&IID_IDirectInputDevice8W, riid)) { - *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, index); - TRACE("Created a Joystick device (%p)\n", *pdev); + JoystickImpl *This = alloc_device(rguid, dinput, index); + TRACE("Created a Joystick device (%p)\n", This); - if (*pdev == NULL) + if (!This) { ERR("out of memory\n"); return DIERR_OUTOFMEMORY; } + *pdev = (IDirectInputDeviceW*) &This->generic.base.IDirectInputDevice8W_iface; return DI_OK; } WARN("no interface\n"); diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c index 672607284d1..19ff6a3f586 100644 --- a/dlls/dinput/joystick_osx.c +++ b/dlls/dinput/joystick_osx.c @@ -137,11 +137,13 @@ struct JoystickImpl static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface) { - return (JoystickImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface), + JoystickGenericImpl, base), JoystickImpl, generic); } static inline JoystickImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) { - return (JoystickImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), + JoystickGenericImpl, base), JoystickImpl, generic); } static const GUID DInput_Wine_OsX_Joystick_GUID = { /* 59CAD8F6-E617-41E2-8EB7-47B23EEEDC5A */ @@ -716,8 +718,8 @@ static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTAN return FALSE; } -static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, - LPDIRECTINPUTDEVICEA* pdev, unsigned short index) +static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput, + JoystickImpl **pdev, unsigned short index) { DWORD i; JoystickImpl* newDevice; @@ -728,7 +730,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di int axis_map[8]; /* max axes */ int slider_count = 0; - TRACE("%s %p %p %p %hu\n", debugstr_guid(rguid), jvt, dinput, pdev, index); + TRACE("%s %p %p %hu\n", debugstr_guid(rguid), dinput, pdev, index); newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl)); if (newDevice == 0) { @@ -763,7 +765,8 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di newDevice->generic.devcaps.dwButtons = 128; } - newDevice->generic.base.lpVtbl = jvt; + newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt; + newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt; newDevice->generic.base.ref = 1; newDevice->generic.base.dinput = dinput; newDevice->generic.base.guid = *rguid; @@ -835,7 +838,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di _dump_DIDEVCAPS(&newDevice->generic.devcaps); } - *pdev = (LPDIRECTINPUTDEVICEA)newDevice; + *pdev = newDevice; return DI_OK; @@ -891,7 +894,11 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, RE IsEqualGUID(&IID_IDirectInputDevice7A, riid) || IsEqualGUID(&IID_IDirectInputDevice8A, riid)) { - return alloc_device(rguid, &JoystickAvt, dinput, pdev, index); + JoystickImpl *This; + HRESULT hr = alloc_device(rguid, dinput, &This, index); + + *pdev = (LPDIRECTINPUTDEVICEA)(This ? &This->generic.base.IDirectInputDevice8A_iface : NULL); + return hr; } WARN("no interface\n"); @@ -921,7 +928,11 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, RE IsEqualGUID(&IID_IDirectInputDevice7W, riid) || IsEqualGUID(&IID_IDirectInputDevice8W, riid)) { - return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA *)pdev, index); + JoystickImpl *This; + HRESULT hr = alloc_device(rguid, dinput, &This, index); + + *pdev = (LPDIRECTINPUTDEVICEW)(This ? &This->generic.base.IDirectInputDevice8W_iface : NULL); + return hr; } WARN("no interface\n"); return DIERR_NOINTERFACE; diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index bdb7a83b4c4..69576623748 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -52,19 +52,19 @@ struct SysKeyboardImpl static inline SysKeyboardImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface) { - return (SysKeyboardImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface), SysKeyboardImpl, base); } static inline SysKeyboardImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) { - return (SysKeyboardImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), SysKeyboardImpl, base); } static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(SysKeyboardImpl *This) { - return (IDirectInputDevice8A *)This; + return &This->base.IDirectInputDevice8A_iface; } static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(SysKeyboardImpl *This) { - return (IDirectInputDevice8W *)This; + return &This->base.IDirectInputDevice8W_iface; } static BYTE map_dik_code(DWORD scanCode, DWORD vkCode) @@ -220,14 +220,15 @@ static BOOL keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEI return FALSE; } -static SysKeyboardImpl *alloc_device(REFGUID rguid, const void *kvt, IDirectInputImpl *dinput) +static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput) { SysKeyboardImpl* newDevice; LPDIDATAFORMAT df = NULL; int i, idx = 0; newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl)); - newDevice->base.lpVtbl = kvt; + newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt; + newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt; newDevice->base.ref = 1; memcpy(&newDevice->base.guid, rguid, sizeof(*rguid)); newDevice->base.dinput = dinput; @@ -273,9 +274,14 @@ static HRESULT keyboarddev_create_deviceA(IDirectInputImpl *dinput, REFGUID rgui IsEqualGUID(&IID_IDirectInputDevice2A,riid) || IsEqualGUID(&IID_IDirectInputDevice7A,riid) || IsEqualGUID(&IID_IDirectInputDevice8A,riid)) { - *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysKeyboardAvt, dinput); + + SysKeyboardImpl *This = alloc_device(rguid, dinput); + if (!This) { + *pdev = NULL; + return DIERR_OUTOFMEMORY; + } + *pdev = (IDirectInputDeviceA*) &This->base.IDirectInputDevice8A_iface; TRACE("Creating a Keyboard device (%p)\n", *pdev); - if (!*pdev) return DIERR_OUTOFMEMORY; return DI_OK; } else return DIERR_NOINTERFACE; @@ -292,9 +298,14 @@ static HRESULT keyboarddev_create_deviceW(IDirectInputImpl *dinput, REFGUID rgui IsEqualGUID(&IID_IDirectInputDevice2W,riid) || IsEqualGUID(&IID_IDirectInputDevice7W,riid) || IsEqualGUID(&IID_IDirectInputDevice8W,riid)) { - *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysKeyboardWvt, dinput); + + SysKeyboardImpl *This = alloc_device(rguid, dinput); + if (!This) { + *pdev = NULL; + return DIERR_OUTOFMEMORY; + } + *pdev = (IDirectInputDeviceW*) &This->base.IDirectInputDevice8W_iface; TRACE("Creating a Keyboard device (%p)\n", *pdev); - if (!*pdev) return DIERR_OUTOFMEMORY; return DI_OK; } else return DIERR_NOINTERFACE; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 943c3c8d2cc..0bdec82b6b2 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -80,19 +80,19 @@ struct SysMouseImpl static inline SysMouseImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface) { - return (SysMouseImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface), SysMouseImpl, base); } static inline SysMouseImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) { - return (SysMouseImpl *) iface; + return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), SysMouseImpl, base); } static inline IDirectInputDevice8A *IDirectInputDevice8A_from_impl(SysMouseImpl *This) { - return (IDirectInputDevice8A *)This; + return &This->base.IDirectInputDevice8A_iface; } static inline IDirectInputDevice8W *IDirectInputDevice8W_from_impl(SysMouseImpl *This) { - return (IDirectInputDevice8W *)This; + return &This->base.IDirectInputDevice8W_iface; } static int dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM lparam ); @@ -196,7 +196,7 @@ static BOOL mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINST return FALSE; } -static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputImpl *dinput) +static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput) { SysMouseImpl* newDevice; LPDIDATAFORMAT df = NULL; @@ -206,7 +206,8 @@ static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputIm newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl)); if (!newDevice) return NULL; - newDevice->base.lpVtbl = mvt; + newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysMouseAvt; + newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysMouseWvt; newDevice->base.ref = 1; newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; newDevice->base.guid = *rguid; @@ -259,9 +260,15 @@ static HRESULT mousedev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, IsEqualGUID(&IID_IDirectInputDevice2A,riid) || IsEqualGUID(&IID_IDirectInputDevice7A,riid) || IsEqualGUID(&IID_IDirectInputDevice8A,riid)) { - *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysMouseAvt, dinput); - TRACE("Creating a Mouse device (%p)\n", *pdev); - if (!*pdev) return DIERR_OUTOFMEMORY; + + SysMouseImpl* This = alloc_device(rguid, dinput); + TRACE("Created a Mouse device (%p)\n", This); + + if (!This) { + *pdev = NULL; + return DIERR_OUTOFMEMORY; + } + *pdev = (IDirectInputDeviceA*) &This->base.IDirectInputDevice8A_iface; return DI_OK; } else return DIERR_NOINTERFACE; @@ -279,9 +286,15 @@ static HRESULT mousedev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, IsEqualGUID(&IID_IDirectInputDevice2W,riid) || IsEqualGUID(&IID_IDirectInputDevice7W,riid) || IsEqualGUID(&IID_IDirectInputDevice8W,riid)) { - *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysMouseWvt, dinput); - TRACE("Creating a Mouse device (%p)\n", *pdev); - if (!*pdev) return DIERR_OUTOFMEMORY; + + SysMouseImpl* This = alloc_device(rguid, dinput); + TRACE("Created a Mouse device (%p)\n", This); + + if (!This) { + *pdev = NULL; + return DIERR_OUTOFMEMORY; + } + *pdev = (IDirectInputDeviceW*) &This->base.IDirectInputDevice8W_iface; return DI_OK; } else return DIERR_NOINTERFACE;