dinput: Implement IDirectInputDevice_EnumObjects WtoA conversion.

Instead of a separate duplicate implementation.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-05-25 18:48:57 +02:00 committed by Alexandre Julliard
parent ab8e416787
commit 9b834bb8bf
2 changed files with 48 additions and 32 deletions

View file

@ -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, &params, flags );
}
HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty( IDirectInputDevice8A *iface_a, REFGUID guid, DIPROPHEADER *header )
{
IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8A( iface_a );

View file

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