Commit 8109f839 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput: Factor out IDirectInputDevice_BuildActionMap WtoA conversions.

parent 27ea33ba
...@@ -90,6 +90,82 @@ static void dieffectinfo_wtoa( const DIEFFECTINFOW *in, DIEFFECTINFOA *out ) ...@@ -90,6 +90,82 @@ static void dieffectinfo_wtoa( const DIEFFECTINFOW *in, DIEFFECTINFOA *out )
WideCharToMultiByte( CP_ACP, 0, in->tszName, -1, out->tszName, sizeof(out->tszName), NULL, NULL ); WideCharToMultiByte( CP_ACP, 0, in->tszName, -1, out->tszName, sizeof(out->tszName), NULL, NULL );
} }
static HRESULT string_atow( const char *in, WCHAR **out )
{
int len;
*out = NULL;
if (!in) return DI_OK;
len = MultiByteToWideChar( CP_ACP, 0, in, -1, NULL, 0 );
if (!(*out = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return DIERR_OUTOFMEMORY;
MultiByteToWideChar( CP_ACP, 0, in, -1, *out, len );
return DI_OK;
}
static void diactionformat_wtoa( const DIACTIONFORMATW *in, DIACTIONFORMATA *out )
{
DWORD i;
out->dwDataSize = in->dwDataSize;
out->dwNumActions = in->dwNumActions;
for (i = 0; i < in->dwNumActions; ++i)
{
out->rgoAction[i].uAppData = in->rgoAction[i].uAppData;
out->rgoAction[i].dwSemantic = in->rgoAction[i].dwSemantic;
out->rgoAction[i].dwFlags = in->rgoAction[i].dwFlags;
out->rgoAction[i].guidInstance = in->rgoAction[i].guidInstance;
out->rgoAction[i].dwObjID = in->rgoAction[i].dwObjID;
out->rgoAction[i].dwHow = in->rgoAction[i].dwHow;
out->rgoAction[i].lptszActionName = 0;
}
out->guidActionMap = in->guidActionMap;
out->dwGenre = in->dwGenre;
out->dwBufferSize = in->dwBufferSize;
out->lAxisMin = in->lAxisMin;
out->lAxisMax = in->lAxisMax;
out->hInstString = in->hInstString;
out->ftTimeStamp = in->ftTimeStamp;
out->dwCRC = in->dwCRC;
WideCharToMultiByte( CP_ACP, 0, in->tszActionMap, -1, out->tszActionMap,
sizeof(out->tszActionMap), NULL, NULL );
}
static void diactionformat_atow( const DIACTIONFORMATA *in, DIACTIONFORMATW *out )
{
DWORD i;
out->dwDataSize = in->dwDataSize;
out->dwNumActions = in->dwNumActions;
for (i = 0; i < out->dwNumActions; ++i)
{
out->rgoAction[i].uAppData = in->rgoAction[i].uAppData;
out->rgoAction[i].dwSemantic = in->rgoAction[i].dwSemantic;
out->rgoAction[i].dwFlags = in->rgoAction[i].dwFlags;
out->rgoAction[i].guidInstance = in->rgoAction[i].guidInstance;
out->rgoAction[i].dwObjID = in->rgoAction[i].dwObjID;
out->rgoAction[i].dwHow = in->rgoAction[i].dwHow;
out->rgoAction[i].lptszActionName = 0;
}
out->guidActionMap = in->guidActionMap;
out->dwGenre = in->dwGenre;
out->dwBufferSize = in->dwBufferSize;
out->lAxisMin = in->lAxisMin;
out->lAxisMax = in->lAxisMax;
out->hInstString = in->hInstString;
out->ftTimeStamp = in->ftTimeStamp;
out->dwCRC = in->dwCRC;
MultiByteToWideChar( CP_ACP, 0, in->tszActionMap, -1, out->tszActionMap,
sizeof(out->tszActionMap) / sizeof(WCHAR) );
}
static void dideviceimageinfo_wtoa( const DIDEVICEIMAGEINFOW *in, DIDEVICEIMAGEINFOA *out ) static void dideviceimageinfo_wtoa( const DIDEVICEIMAGEINFOW *in, DIDEVICEIMAGEINFOA *out )
{ {
WideCharToMultiByte( CP_ACP, 0, in->tszImagePath, -1, out->tszImagePath, WideCharToMultiByte( CP_ACP, 0, in->tszImagePath, -1, out->tszImagePath,
...@@ -416,6 +492,35 @@ HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile( IDirectInputDevice8A ...@@ -416,6 +492,35 @@ HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile( IDirectInputDevice8A
return IDirectInputDevice8_WriteEffectToFile( iface_w, filename_w, entries, file_effect, flags ); return IDirectInputDevice8_WriteEffectToFile( iface_w, filename_w, entries, file_effect, flags );
} }
HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap( IDirectInputDevice8A *iface_a, DIACTIONFORMATA *format_a,
const char *username_a, DWORD flags )
{
IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8A( iface_a );
IDirectInputDevice8W *iface_w = IDirectInputDevice8W_from_impl( impl );
DIACTIONFORMATW format_w = {sizeof(format_w), sizeof(DIACTIONW)};
HRESULT hr;
WCHAR *username_w;
if (!format_a) return E_POINTER;
if (format_a->dwSize != sizeof(DIACTIONFORMATA)) return DIERR_INVALIDPARAM;
if (format_a->dwActionSize != sizeof(DIACTIONA)) return DIERR_INVALIDPARAM;
if (FAILED(hr = string_atow( username_a, &username_w ))) return hr;
format_w.dwNumActions = format_a->dwNumActions;
format_w.rgoAction = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, format_a->dwNumActions * sizeof(DIACTIONW) );
if (!format_w.rgoAction) hr = DIERR_OUTOFMEMORY;
else
{
diactionformat_atow( format_a, &format_w );
hr = IDirectInputDevice8_BuildActionMap( iface_w, &format_w, username_w, flags );
diactionformat_wtoa( &format_w, format_a );
HeapFree( GetProcessHeap(), 0, format_w.rgoAction );
}
HeapFree( GetProcessHeap(), 0, username_w );
return hr;
}
HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo( IDirectInputDevice8A *iface_a, DIDEVICEIMAGEINFOHEADERA *header_a ) HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo( IDirectInputDevice8A *iface_a, DIDEVICEIMAGEINFOHEADERA *header_a )
{ {
IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8A( iface_a ); IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8A( iface_a );
......
...@@ -248,6 +248,8 @@ extern HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVIC ...@@ -248,6 +248,8 @@ extern HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVIC
LPDIACTIONFORMATW lpdiaf, LPDIACTIONFORMATW lpdiaf,
LPCWSTR lpszUserName, LPCWSTR lpszUserName,
DWORD dwFlags) DECLSPEC_HIDDEN; DWORD dwFlags) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap( LPDIRECTINPUTDEVICE8A iface, DIACTIONFORMATA *format,
const char *username, DWORD flags ) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface, extern HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader) DECLSPEC_HIDDEN; LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface, extern HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
......
...@@ -773,36 +773,6 @@ HRESULT WINAPI JoystickWGenericImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface, ...@@ -773,36 +773,6 @@ HRESULT WINAPI JoystickWGenericImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags); return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
} }
HRESULT WINAPI JoystickAGenericImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
LPDIACTIONFORMATA lpdiaf,
LPCSTR lpszUserName,
DWORD dwFlags)
{
JoystickGenericImpl *This = impl_from_IDirectInputDevice8A(iface);
DIACTIONFORMATW diafW;
HRESULT hr;
WCHAR *lpszUserNameW = NULL;
int username_size;
diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
_copy_diactionformatAtoW(&diafW, lpdiaf);
if (lpszUserName != NULL)
{
username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
}
hr = JoystickWGenericImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
_copy_diactionformatWtoA(lpdiaf, &diafW);
HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
HeapFree(GetProcessHeap(), 0, lpszUserNameW);
return hr;
}
HRESULT WINAPI JoystickWGenericImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface, HRESULT WINAPI JoystickWGenericImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
LPDIACTIONFORMATW lpdiaf, LPDIACTIONFORMATW lpdiaf,
LPCWSTR lpszUserName, LPCWSTR lpszUserName,
......
...@@ -909,7 +909,7 @@ static const IDirectInputDevice8AVtbl JoystickAvt = ...@@ -909,7 +909,7 @@ static const IDirectInputDevice8AVtbl JoystickAvt =
IDirectInputDevice2AImpl_SendDeviceData, IDirectInputDevice2AImpl_SendDeviceData,
IDirectInputDevice7AImpl_EnumEffectsInFile, IDirectInputDevice7AImpl_EnumEffectsInFile,
IDirectInputDevice7AImpl_WriteEffectToFile, IDirectInputDevice7AImpl_WriteEffectToFile,
JoystickAGenericImpl_BuildActionMap, IDirectInputDevice8AImpl_BuildActionMap,
JoystickAGenericImpl_SetActionMap, JoystickAGenericImpl_SetActionMap,
IDirectInputDevice8AImpl_GetImageInfo IDirectInputDevice8AImpl_GetImageInfo
}; };
......
...@@ -1339,7 +1339,7 @@ static const IDirectInputDevice8AVtbl JoystickAvt = ...@@ -1339,7 +1339,7 @@ static const IDirectInputDevice8AVtbl JoystickAvt =
IDirectInputDevice2AImpl_SendDeviceData, IDirectInputDevice2AImpl_SendDeviceData,
IDirectInputDevice7AImpl_EnumEffectsInFile, IDirectInputDevice7AImpl_EnumEffectsInFile,
IDirectInputDevice7AImpl_WriteEffectToFile, IDirectInputDevice7AImpl_WriteEffectToFile,
JoystickAGenericImpl_BuildActionMap, IDirectInputDevice8AImpl_BuildActionMap,
JoystickAGenericImpl_SetActionMap, JoystickAGenericImpl_SetActionMap,
IDirectInputDevice8AImpl_GetImageInfo IDirectInputDevice8AImpl_GetImageInfo
}; };
......
...@@ -1600,7 +1600,7 @@ static const IDirectInputDevice8AVtbl JoystickAvt = ...@@ -1600,7 +1600,7 @@ static const IDirectInputDevice8AVtbl JoystickAvt =
IDirectInputDevice2AImpl_SendDeviceData, IDirectInputDevice2AImpl_SendDeviceData,
IDirectInputDevice7AImpl_EnumEffectsInFile, IDirectInputDevice7AImpl_EnumEffectsInFile,
IDirectInputDevice7AImpl_WriteEffectToFile, IDirectInputDevice7AImpl_WriteEffectToFile,
JoystickAGenericImpl_BuildActionMap, IDirectInputDevice8AImpl_BuildActionMap,
JoystickAGenericImpl_SetActionMap, JoystickAGenericImpl_SetActionMap,
IDirectInputDevice8AImpl_GetImageInfo IDirectInputDevice8AImpl_GetImageInfo
}; };
......
...@@ -77,7 +77,6 @@ HRESULT WINAPI JoystickWGenericImpl_Poll(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_H ...@@ -77,7 +77,6 @@ HRESULT WINAPI JoystickWGenericImpl_Poll(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_H
HRESULT WINAPI JoystickWGenericImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr) DECLSPEC_HIDDEN; HRESULT WINAPI JoystickWGenericImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr) DECLSPEC_HIDDEN;
HRESULT WINAPI JoystickAGenericImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface, LPDIACTIONFORMATA lpdiaf, LPCSTR lpszUserName, DWORD dwFlags) DECLSPEC_HIDDEN;
HRESULT WINAPI JoystickWGenericImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags) DECLSPEC_HIDDEN; HRESULT WINAPI JoystickWGenericImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags) DECLSPEC_HIDDEN;
HRESULT WINAPI JoystickAGenericImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface, LPDIACTIONFORMATA lpdiaf, LPCSTR lpszUserName, DWORD dwFlags) DECLSPEC_HIDDEN; HRESULT WINAPI JoystickAGenericImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface, LPDIACTIONFORMATA lpdiaf, LPCSTR lpszUserName, DWORD dwFlags) DECLSPEC_HIDDEN;
......
...@@ -554,36 +554,6 @@ static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W ifac ...@@ -554,36 +554,6 @@ static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W ifac
return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIKEYBOARD_MASK, &c_dfDIKeyboard); return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIKEYBOARD_MASK, &c_dfDIKeyboard);
} }
static HRESULT WINAPI SysKeyboardAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
LPDIACTIONFORMATA lpdiaf,
LPCSTR lpszUserName,
DWORD dwFlags)
{
SysKeyboardImpl *This = impl_from_IDirectInputDevice8A(iface);
DIACTIONFORMATW diafW;
HRESULT hr;
WCHAR *lpszUserNameW = NULL;
int username_size;
diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
_copy_diactionformatAtoW(&diafW, lpdiaf);
if (lpszUserName != NULL)
{
username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
}
hr = SysKeyboardWImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
_copy_diactionformatWtoA(lpdiaf, &diafW);
HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
HeapFree(GetProcessHeap(), 0, lpszUserNameW);
return hr;
}
static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface, static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
LPDIACTIONFORMATW lpdiaf, LPDIACTIONFORMATW lpdiaf,
LPCWSTR lpszUserName, LPCWSTR lpszUserName,
...@@ -655,7 +625,7 @@ static const IDirectInputDevice8AVtbl SysKeyboardAvt = ...@@ -655,7 +625,7 @@ static const IDirectInputDevice8AVtbl SysKeyboardAvt =
IDirectInputDevice2AImpl_SendDeviceData, IDirectInputDevice2AImpl_SendDeviceData,
IDirectInputDevice7AImpl_EnumEffectsInFile, IDirectInputDevice7AImpl_EnumEffectsInFile,
IDirectInputDevice7AImpl_WriteEffectToFile, IDirectInputDevice7AImpl_WriteEffectToFile,
SysKeyboardAImpl_BuildActionMap, IDirectInputDevice8AImpl_BuildActionMap,
SysKeyboardAImpl_SetActionMap, SysKeyboardAImpl_SetActionMap,
IDirectInputDevice8AImpl_GetImageInfo IDirectInputDevice8AImpl_GetImageInfo
}; };
......
...@@ -807,36 +807,6 @@ static HRESULT WINAPI SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface, ...@@ -807,36 +807,6 @@ static HRESULT WINAPI SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIMOUSE_MASK, &c_dfDIMouse2); return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIMOUSE_MASK, &c_dfDIMouse2);
} }
static HRESULT WINAPI SysMouseAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
LPDIACTIONFORMATA lpdiaf,
LPCSTR lpszUserName,
DWORD dwFlags)
{
SysMouseImpl *This = impl_from_IDirectInputDevice8A(iface);
DIACTIONFORMATW diafW;
HRESULT hr;
WCHAR *lpszUserNameW = NULL;
int username_size;
diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiaf->dwNumActions);
_copy_diactionformatAtoW(&diafW, lpdiaf);
if (lpszUserName != NULL)
{
username_size = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
lpszUserNameW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*username_size);
MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, lpszUserNameW, username_size);
}
hr = SysMouseWImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
_copy_diactionformatWtoA(lpdiaf, &diafW);
HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
HeapFree(GetProcessHeap(), 0, lpszUserNameW);
return hr;
}
static HRESULT WINAPI SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface, static HRESULT WINAPI SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
LPDIACTIONFORMATW lpdiaf, LPDIACTIONFORMATW lpdiaf,
LPCWSTR lpszUserName, LPCWSTR lpszUserName,
...@@ -908,7 +878,7 @@ static const IDirectInputDevice8AVtbl SysMouseAvt = ...@@ -908,7 +878,7 @@ static const IDirectInputDevice8AVtbl SysMouseAvt =
IDirectInputDevice2AImpl_SendDeviceData, IDirectInputDevice2AImpl_SendDeviceData,
IDirectInputDevice7AImpl_EnumEffectsInFile, IDirectInputDevice7AImpl_EnumEffectsInFile,
IDirectInputDevice7AImpl_WriteEffectToFile, IDirectInputDevice7AImpl_WriteEffectToFile,
SysMouseAImpl_BuildActionMap, IDirectInputDevice8AImpl_BuildActionMap,
SysMouseAImpl_SetActionMap, SysMouseAImpl_SetActionMap,
IDirectInputDevice8AImpl_GetImageInfo IDirectInputDevice8AImpl_GetImageInfo
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment