Instead of a separate duplicate implementation.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/ansi.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ dlls/dinput/device.c | 32 ----------------------------- 2 files changed, 48 insertions(+), 32 deletions(-)
diff --git a/dlls/dinput/ansi.c b/dlls/dinput/ansi.c index 99156195423..5158d326073 100644 --- a/dlls/dinput/ansi.c +++ b/dlls/dinput/ansi.c @@ -43,6 +43,27 @@ static IDirectInputDevice8W *IDirectInputDevice8W_from_impl( IDirectInputDeviceI return &impl->IDirectInputDevice8W_iface; }
+static void dideviceobjectinstance_wtoa( const DIDEVICEOBJECTINSTANCEW *in, DIDEVICEOBJECTINSTANCEA *out ) +{ + out->guidType = in->guidType; + out->dwOfs = in->dwOfs; + out->dwType = in->dwType; + out->dwFlags = in->dwFlags; + WideCharToMultiByte( CP_ACP, 0, in->tszName, -1, out->tszName, sizeof(out->tszName), NULL, NULL ); + + if (out->dwSize <= FIELD_OFFSET( DIDEVICEOBJECTINSTANCEA, dwFFMaxForce )) return; + + out->dwFFMaxForce = in->dwFFMaxForce; + out->dwFFForceResolution = in->dwFFForceResolution; + out->wCollectionNumber = in->wCollectionNumber; + out->wDesignatorIndex = in->wDesignatorIndex; + out->wUsagePage = in->wUsagePage; + out->wUsage = in->wUsage; + out->dwDimension = in->dwDimension; + out->wExponent = in->wExponent; + out->wReserved = in->wReserved; +} + HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface( IDirectInputDevice8A *iface_a, REFIID iid, void **out ) { IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8A( iface_a ); @@ -64,6 +85,33 @@ ULONG WINAPI IDirectInputDevice2AImpl_Release( IDirectInputDevice8A *iface_a ) return IDirectInputDevice8_Release( iface_w ); }
+struct enum_objects_wtoa_params +{ + LPDIENUMDEVICEOBJECTSCALLBACKA callback; + void *ref; +}; + +static BOOL CALLBACK enum_objects_wtoa_callback( const DIDEVICEOBJECTINSTANCEW *instance_w, void *ref ) +{ + struct enum_objects_wtoa_params *params = ref; + DIDEVICEOBJECTINSTANCEA instance_a = {sizeof(instance_a)}; + + dideviceobjectinstance_wtoa( instance_w, &instance_a ); + return params->callback( &instance_a, params->ref ); +} + +HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects( IDirectInputDevice8A *iface_a, LPDIENUMDEVICEOBJECTSCALLBACKA callback, + void *ref, DWORD flags ) +{ + struct enum_objects_wtoa_params params = {callback, ref}; + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8A( iface_a ); + IDirectInputDevice8W *iface_w = IDirectInputDevice8W_from_impl( impl ); + + if (!callback) return DIERR_INVALIDPARAM; + + return IDirectInputDevice8_EnumObjects( iface_w, enum_objects_wtoa_callback, ¶ms, flags ); +} + HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty( IDirectInputDevice8A *iface_a, REFGUID guid, DIPROPHEADER *header ) { IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8A( iface_a ); diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index c6385e6c025..31b859801c7 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1247,38 +1247,6 @@ ULONG WINAPI IDirectInputDevice2WImpl_AddRef(LPDIRECTINPUTDEVICE8W iface) return ref; }
-HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(LPDIRECTINPUTDEVICE8A iface, - LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback, LPVOID lpvRef, DWORD dwFlags) -{ - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8A(iface); - DIDEVICEOBJECTINSTANCEA ddoi; - int i; - - TRACE("(%p)->(%p,%p flags:%08x)\n", This, lpCallback, lpvRef, dwFlags); - TRACE(" - flags = "); - _dump_EnumObjects_flags(dwFlags); - TRACE("\n"); - - if (!lpCallback) return DIERR_INVALIDPARAM; - - /* Only the fields till dwFFMaxForce are relevant */ - memset(&ddoi, 0, sizeof(ddoi)); - ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce); - - for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++) - { - LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i); - - if (dwFlags != DIDFT_ALL && !(dwFlags & DIDFT_GETTYPE(odf->dwType))) continue; - if (IDirectInputDevice_GetObjectInfo(iface, &ddoi, odf->dwType, DIPH_BYID) != DI_OK) - continue; - - if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) break; - } - - return DI_OK; -} - HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface, LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef, DWORD dwFlags) {