[PATCH 4/6] dinput: Factor out IDirectInputDevice_GetDeviceInfo WtoA conversions.
Rémi Bernon
rbernon at codeweavers.com
Thu May 27 03:50:03 CDT 2021
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
dlls/dinput/ansi.c | 34 ++++++++++++++++++++++
dlls/dinput/device_private.h | 1 +
dlls/dinput/joystick.c | 48 -------------------------------
dlls/dinput/joystick_linux.c | 26 +----------------
dlls/dinput/joystick_linuxinput.c | 27 +----------------
dlls/dinput/joystick_osx.c | 7 +----
dlls/dinput/joystick_private.h | 3 --
dlls/dinput/keyboard.c | 14 +--------
dlls/dinput/mouse.c | 14 +--------
9 files changed, 40 insertions(+), 134 deletions(-)
diff --git a/dlls/dinput/ansi.c b/dlls/dinput/ansi.c
index c488353aa12..a8e5256bfc6 100644
--- a/dlls/dinput/ansi.c
+++ b/dlls/dinput/ansi.c
@@ -64,6 +64,23 @@ static void dideviceobjectinstance_wtoa( const DIDEVICEOBJECTINSTANCEW *in, DIDE
out->wReserved = in->wReserved;
}
+static void dideviceinstance_wtoa( const DIDEVICEINSTANCEW *in, DIDEVICEINSTANCEA *out )
+{
+ out->guidInstance = in->guidInstance;
+ out->guidProduct = in->guidProduct;
+ out->dwDevType = in->dwDevType;
+ WideCharToMultiByte( CP_ACP, 0, in->tszInstanceName, -1, out->tszInstanceName,
+ sizeof(out->tszInstanceName), NULL, NULL );
+ WideCharToMultiByte( CP_ACP, 0, in->tszProductName, -1, out->tszProductName,
+ sizeof(out->tszProductName), NULL, NULL );
+
+ if (out->dwSize <= FIELD_OFFSET( DIDEVICEINSTANCEA, guidFFDriver )) return;
+
+ out->guidFFDriver = in->guidFFDriver;
+ out->wUsagePage = in->wUsagePage;
+ out->wUsage = in->wUsage;
+}
+
static void dieffectinfo_wtoa( const DIEFFECTINFOW *in, DIEFFECTINFOA *out )
{
out->guid = in->guid;
@@ -247,6 +264,23 @@ HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo( IDirectInputDevice8A *ifa
return hr;
}
+HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo( IDirectInputDevice8A *iface_a, DIDEVICEINSTANCEA *instance_a )
+{
+ IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8A( iface_a );
+ IDirectInputDevice8W *iface_w = IDirectInputDevice8W_from_impl( impl );
+ DIDEVICEINSTANCEW instance_w = {sizeof(instance_w)};
+ HRESULT hr;
+
+ if (!instance_a) return E_POINTER;
+ if (instance_a->dwSize != sizeof(DIDEVICEINSTANCEA) && instance_a->dwSize != sizeof(DIDEVICEINSTANCE_DX3A))
+ return DIERR_INVALIDPARAM;
+
+ hr = IDirectInputDevice8_GetDeviceInfo( iface_w, &instance_w );
+ dideviceinstance_wtoa( &instance_w, instance_a );
+
+ return hr;
+}
+
HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel( IDirectInputDevice8A *iface_a, HWND owner, DWORD flags )
{
IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8A( iface_a );
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h
index 425b0971351..0bebc36076d 100644
--- a/dlls/dinput/device_private.h
+++ b/dlls/dinput/device_private.h
@@ -173,6 +173,7 @@ extern HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(LPDIRECTINPUTDEVICE
LPDIDEVICEOBJECTINSTANCEW pdidoi,
DWORD dwObj,
DWORD dwHow) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface, DIDEVICEINSTANCEA *instance ) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
LPDWORD entries, DWORD flags) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c
index 906f47087fb..d048e0f821f 100644
--- a/dlls/dinput/joystick.c
+++ b/dlls/dinput/joystick.c
@@ -637,54 +637,6 @@ HRESULT WINAPI JoystickWGenericImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REF
return DI_OK;
}
-/******************************************************************************
- * GetDeviceInfo : get information about a device's identity
- */
-HRESULT WINAPI JoystickAGenericImpl_GetDeviceInfo(
- LPDIRECTINPUTDEVICE8A iface,
- LPDIDEVICEINSTANCEA pdidi)
-{
- JoystickGenericImpl *This = impl_from_IDirectInputDevice8A(iface);
- DIPROPDWORD pd;
- DWORD index = 0;
-
- TRACE("(%p,%p)\n", This, pdidi);
-
- if (pdidi == NULL) {
- WARN("invalid pointer\n");
- return E_POINTER;
- }
-
- if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
- (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA))) {
- WARN("invalid parameter: pdidi->dwSize = %d\n", pdidi->dwSize);
- return DIERR_INVALIDPARAM;
- }
-
- /* Try to get joystick index */
- pd.diph.dwSize = sizeof(pd);
- pd.diph.dwHeaderSize = sizeof(pd.diph);
- pd.diph.dwObj = 0;
- pd.diph.dwHow = DIPH_DEVICE;
- if (SUCCEEDED(IDirectInputDevice2_GetProperty(iface, DIPROP_JOYSTICKID, &pd.diph)))
- index = pd.dwData;
-
- /* Return joystick */
- pdidi->guidInstance = This->base.guid;
- pdidi->guidProduct = This->guidProduct;
- /* we only support traditional joysticks for now */
- pdidi->dwDevType = This->devcaps.dwDevType;
- snprintf(pdidi->tszInstanceName, MAX_PATH, "Joystick %d", index);
- lstrcpynA(pdidi->tszProductName, This->name, MAX_PATH);
- if (pdidi->dwSize > sizeof(DIDEVICEINSTANCE_DX3A)) {
- pdidi->guidFFDriver = GUID_NULL;
- pdidi->wUsagePage = 0;
- pdidi->wUsage = 0;
- }
-
- return DI_OK;
-}
-
/******************************************************************************
* GetDeviceInfo : get information about a device's identity
*/
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index e81733a74dd..8290eef0bcb 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -103,11 +103,6 @@ struct JoystickImpl
POINTL povs[4];
};
-static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *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 CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface),
@@ -764,25 +759,6 @@ static HRESULT WINAPI JoystickLinuxWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface
/******************************************************************************
* GetDeviceInfo : get information about a device's identity
*/
-static HRESULT WINAPI JoystickLinuxAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface, LPDIDEVICEINSTANCEA ddi)
-{
- JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
-
- TRACE("(%p) %p\n", This, ddi);
-
- if (ddi == NULL) return E_POINTER;
- if ((ddi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
- (ddi->dwSize != sizeof(DIDEVICEINSTANCEA)))
- return DIERR_INVALIDPARAM;
-
- fill_joystick_dideviceinstanceA( ddi, This->generic.base.dinput->dwVersion,
- get_joystick_index(&This->generic.base.guid) );
-
- ddi->guidInstance = This->generic.base.guid;
-
- return DI_OK;
-}
-
static HRESULT WINAPI JoystickLinuxWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW ddi)
{
JoystickImpl *This = impl_from_IDirectInputDevice8W(iface);
@@ -919,7 +895,7 @@ static const IDirectInputDevice8AVtbl JoystickAvt =
IDirectInputDevice2AImpl_SetEventNotification,
IDirectInputDevice2AImpl_SetCooperativeLevel,
IDirectInputDevice2AImpl_GetObjectInfo,
- JoystickLinuxAImpl_GetDeviceInfo,
+ IDirectInputDevice2AImpl_GetDeviceInfo,
IDirectInputDevice2AImpl_RunControlPanel,
IDirectInputDevice2AImpl_Initialize,
IDirectInputDevice2AImpl_CreateEffect,
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 2a6c73766f4..dd59976719a 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -136,11 +136,6 @@ struct JoystickImpl
int ff_gain;
};
-static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *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 CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface),
@@ -1293,26 +1288,6 @@ static HRESULT WINAPI JoystickWImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE
/******************************************************************************
* GetDeviceInfo : get information about a device's identity
*/
-static HRESULT WINAPI JoystickAImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8A iface,
- LPDIDEVICEINSTANCEA pdidi)
-{
- JoystickImpl *This = impl_from_IDirectInputDevice8A(iface);
-
- TRACE("(%p) %p\n", This, pdidi);
-
- if (pdidi == NULL) return E_POINTER;
- if ((pdidi->dwSize != sizeof(DIDEVICEINSTANCE_DX3A)) &&
- (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)))
- return DIERR_INVALIDPARAM;
-
- fill_joystick_dideviceinstanceA(pdidi, This->generic.base.dinput->dwVersion,
- get_joystick_index(&This->generic.base.guid));
-
- pdidi->guidInstance = This->generic.base.guid;
-
- return DI_OK;
-}
-
static HRESULT WINAPI JoystickWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface,
LPDIDEVICEINSTANCEW pdidi)
{
@@ -1350,7 +1325,7 @@ static const IDirectInputDevice8AVtbl JoystickAvt =
IDirectInputDevice2AImpl_SetEventNotification,
IDirectInputDevice2AImpl_SetCooperativeLevel,
IDirectInputDevice2AImpl_GetObjectInfo,
- JoystickAImpl_GetDeviceInfo,
+ IDirectInputDevice2AImpl_GetDeviceInfo,
IDirectInputDevice2AImpl_RunControlPanel,
IDirectInputDevice2AImpl_Initialize,
IDirectInputDevice2AImpl_CreateEffect,
diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c
index 98865253570..b72322e0bd6 100644
--- a/dlls/dinput/joystick_osx.c
+++ b/dlls/dinput/joystick_osx.c
@@ -116,11 +116,6 @@ struct JoystickImpl
struct list effects;
};
-static inline JoystickImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *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 CONTAINING_RECORD(CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface),
@@ -1591,7 +1586,7 @@ static const IDirectInputDevice8AVtbl JoystickAvt =
IDirectInputDevice2AImpl_SetEventNotification,
IDirectInputDevice2AImpl_SetCooperativeLevel,
IDirectInputDevice2AImpl_GetObjectInfo,
- JoystickAGenericImpl_GetDeviceInfo,
+ IDirectInputDevice2AImpl_GetDeviceInfo,
IDirectInputDevice2AImpl_RunControlPanel,
IDirectInputDevice2AImpl_Initialize,
IDirectInputDevice2AImpl_CreateEffect,
diff --git a/dlls/dinput/joystick_private.h b/dlls/dinput/joystick_private.h
index 62e453a7835..235ec962fb8 100644
--- a/dlls/dinput/joystick_private.h
+++ b/dlls/dinput/joystick_private.h
@@ -70,9 +70,6 @@ void _dump_DIDEVCAPS(const DIDEVCAPS *lpDIDevCaps) DECLSPEC_HIDDEN;
HRESULT WINAPI JoystickWGenericImpl_SetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIPROPHEADER ph) DECLSPEC_HIDDEN;
-HRESULT WINAPI JoystickAGenericImpl_GetDeviceInfo( LPDIRECTINPUTDEVICE8A iface,
- LPDIDEVICEINSTANCEA pdidi) DECLSPEC_HIDDEN;
-
HRESULT WINAPI JoystickWGenericImpl_GetDeviceInfo( LPDIRECTINPUTDEVICE8W iface,
LPDIDEVICEINSTANCEW pdidi) DECLSPEC_HIDDEN;
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 010722efd8c..d9c3f02e669 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -471,18 +471,6 @@ static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
/******************************************************************************
* GetDeviceInfo : get information about a device's identity
*/
-static HRESULT WINAPI SysKeyboardAImpl_GetDeviceInfo(
- LPDIRECTINPUTDEVICE8A iface,
- LPDIDEVICEINSTANCEA pdidi)
-{
- SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
- TRACE("(this=%p,%p)\n", This, pdidi);
-
- fill_keyboard_dideviceinstanceA(pdidi, This->base.dinput->dwVersion, This->subtype);
-
- return DI_OK;
-}
-
static HRESULT WINAPI SysKeyboardWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
{
SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
@@ -653,7 +641,7 @@ static const IDirectInputDevice8AVtbl SysKeyboardAvt =
IDirectInputDevice2AImpl_SetEventNotification,
IDirectInputDevice2AImpl_SetCooperativeLevel,
IDirectInputDevice2AImpl_GetObjectInfo,
- SysKeyboardAImpl_GetDeviceInfo,
+ IDirectInputDevice2AImpl_GetDeviceInfo,
IDirectInputDevice2AImpl_RunControlPanel,
IDirectInputDevice2AImpl_Initialize,
IDirectInputDevice2AImpl_CreateEffect,
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 849712a49ca..f5f6bf2214a 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -782,18 +782,6 @@ static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
/******************************************************************************
* GetDeviceInfo : get information about a device's identity
*/
-static HRESULT WINAPI SysMouseAImpl_GetDeviceInfo(
- LPDIRECTINPUTDEVICE8A iface,
- LPDIDEVICEINSTANCEA pdidi)
-{
- SysMouseImpl *This = impl_from_IDirectInputDevice8A(iface);
- TRACE("(this=%p,%p)\n", This, pdidi);
-
- fill_mouse_dideviceinstanceA(pdidi, This->base.dinput->dwVersion);
-
- return DI_OK;
-}
-
static HRESULT WINAPI SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
{
SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
@@ -906,7 +894,7 @@ static const IDirectInputDevice8AVtbl SysMouseAvt =
IDirectInputDevice2AImpl_SetEventNotification,
IDirectInputDevice2AImpl_SetCooperativeLevel,
IDirectInputDevice2AImpl_GetObjectInfo,
- SysMouseAImpl_GetDeviceInfo,
+ IDirectInputDevice2AImpl_GetDeviceInfo,
IDirectInputDevice2AImpl_RunControlPanel,
IDirectInputDevice2AImpl_Initialize,
IDirectInputDevice2AImpl_CreateEffect,
--
2.31.0
More information about the wine-devel
mailing list