Skip to content

Instantly share code, notes, and snippets.

@lfzawacki
Created August 15, 2011 13:56
Show Gist options
  • Save lfzawacki/1146808 to your computer and use it in GitHub Desktop.
Save lfzawacki/1146808 to your computer and use it in GitHub Desktop.
Wine dinput8 Refactoring
From 38582e4da1cce9d750f0d7b30e8b320bafd7e07e Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <[email protected]>
Date: Thu, 21 Jul 2011 16:15:34 -0300
Subject: dinput: Common implementation of BuildActionMap for keyboard and mouse
---
dlls/dinput/device.c | 45 ++++++++++++++++++++++++++++++++++++++++++
dlls/dinput/device_private.h | 2 +
dlls/dinput/keyboard.c | 28 +-------------------------
dlls/dinput/mouse.c | 28 +------------------------
4 files changed, 50 insertions(+), 53 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index 8719066..77182c1 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -598,6 +598,51 @@ DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic)
return type | (0x0000ff00 & (obj_instance << 8));
}
+HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df)
+{
+ IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
+ int i, has_actions = 0;
+
+ for (i=0; i < lpdiaf->dwNumActions; i++)
+ {
+ /* Don't touch an user configured action */
+ if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
+
+ if ((lpdiaf->rgoAction[i].dwSemantic & devMask) == devMask)
+ {
+ DWORD obj_id = semantic_to_obj_id(This, lpdiaf->rgoAction[i].dwSemantic);
+ DWORD type = DIDFT_GETTYPE(obj_id);
+ DWORD inst = DIDFT_GETINSTANCE(obj_id);
+
+ LPDIOBJECTDATAFORMAT odf;
+
+ if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
+ if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
+
+ /* Assure that the object exists */
+ odf = dataformat_to_odf_by_type(df, inst, type);
+
+ if (odf != NULL)
+ {
+ lpdiaf->rgoAction[i].dwObjID = obj_id;
+ lpdiaf->rgoAction[i].guidInstance = This->guid;
+ lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
+ has_actions = 1;
+ }
+ }
+ else if (!(dwFlags & DIDBAM_PRESERVE))
+ {
+ /* we must clear action data belonging to other devices */
+ memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
+ lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
+ }
+ }
+
+ if (!has_actions) return DI_NOEFFECT;
+
+ return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
+}
+
/******************************************************************************
* queue_event - add new event to the ring queue
*/
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h
index e8fe00a..9b7b370 100644
--- a/dlls/dinput/device_private.h
+++ b/dlls/dinput/device_private.h
@@ -127,6 +127,8 @@ extern const char *_dump_dinput_GUID(const GUID *guid) DECLSPEC_HIDDEN;
extern DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic) DECLSPEC_HIDDEN;
extern LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD type) DECLSPEC_HIDDEN;
+extern HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN;
+
/* And the stubs */
extern HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface) DECLSPEC_HIDDEN;
extern HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN;
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 4354a68..1f766fc 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -529,35 +529,9 @@ static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W ifac
LPCWSTR lpszUserName,
DWORD dwFlags)
{
- SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
- int i, has_actions = 0;
-
FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
- for (i=0; i < lpdiaf->dwNumActions; i++)
- {
- if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
-
- if ((lpdiaf->rgoAction[i].dwSemantic & DIKEYBOARD_MASK) == DIKEYBOARD_MASK)
- {
- DWORD obj_id = semantic_to_obj_id(&This->base, lpdiaf->rgoAction[i].dwSemantic);
-
- lpdiaf->rgoAction[i].dwObjID = obj_id;
- lpdiaf->rgoAction[i].guidInstance = This->base.guid;
- lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
- has_actions = 1;
- }
- else if (!(dwFlags & DIDBAM_PRESERVE))
- {
- /* we must clear action data belonging to other devices */
- memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
- lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
- }
- }
-
- if (!has_actions) return DI_NOEFFECT;
-
- return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
+ return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIKEYBOARD_MASK, &c_dfDIKeyboard);
}
static HRESULT WINAPI SysKeyboardAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index fe4faef..f42cdb5 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -778,33 +778,9 @@ static HRESULT WINAPI SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
LPCWSTR lpszUserName,
DWORD dwFlags)
{
- SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
- int i, has_actions = 0;
-
- for (i=0; i < lpdiaf->dwNumActions; i++)
- {
- if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
-
- if ((lpdiaf->rgoAction[i].dwSemantic & DIMOUSE_MASK) == DIMOUSE_MASK)
- {
- DWORD obj_id = semantic_to_obj_id(&This->base, lpdiaf->rgoAction[i].dwSemantic);
-
- lpdiaf->rgoAction[i].dwObjID = obj_id;
- lpdiaf->rgoAction[i].guidInstance = This->base.guid;
- lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT;
- has_actions = 1;
- }
- else if (!(dwFlags & DIDBAM_PRESERVE))
- {
- /* we must clear action data belonging to other devices */
- memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID));
- lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED;
- }
- }
-
- if (!has_actions) return DI_NOEFFECT;
+ FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
- return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
+ return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIMOUSE_MASK, &c_dfDIMouse2);
}
static HRESULT WINAPI SysMouseAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
--
1.7.0.4
From 2de6916f6dcbff47e88da4b9bf71dfd39bdb6afa Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <[email protected]>
Date: Tue, 9 Aug 2011 16:46:06 -0300
Subject: dinput: Common implementation for joystick, keyboard and mouse SetActionMap
---
dlls/dinput/device.c | 106 +++++++++++++++++++++++++++++++++---------
dlls/dinput/device_private.h | 1 +
dlls/dinput/joystick.c | 58 +----------------------
dlls/dinput/keyboard.c | 48 +------------------
dlls/dinput/mouse.c | 52 +--------------------
5 files changed, 90 insertions(+), 175 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index 77182c1..d2de525 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -643,6 +643,87 @@ HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf,
return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags);
}
+HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df)
+{
+ IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
+ DIDATAFORMAT data_format;
+ DIOBJECTDATAFORMAT *obj_df = NULL;
+ DIPROPDWORD dp;
+ DIPROPRANGE dpr;
+ int i, action = 0, num_actions = 0;
+ unsigned int offset = 0;
+
+ if (This->acquired) return DIERR_ACQUIRED;
+
+ data_format.dwSize = sizeof(data_format);
+ data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
+ data_format.dwFlags = DIDF_RELAXIS;
+ data_format.dwDataSize = lpdiaf->dwDataSize;
+
+ /* Count the actions */
+ for (i=0; i < lpdiaf->dwNumActions; i++)
+ if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
+ num_actions++;
+
+ if (num_actions == 0) return DI_NOEFFECT;
+
+ This->num_actions = num_actions;
+
+ /* Construct the dataformat and actionmap */
+ obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
+ data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
+ data_format.dwNumObjs = num_actions;
+
+ This->action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
+
+ for (i = 0; i < lpdiaf->dwNumActions; i++)
+ {
+ if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance))
+ {
+ DWORD inst = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
+ DWORD type = DIDFT_GETTYPE(lpdiaf->rgoAction[i].dwObjID);
+ LPDIOBJECTDATAFORMAT obj;
+
+ if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
+ if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
+
+ obj = dataformat_to_odf_by_type(df, inst, type);
+
+ memcpy(&obj_df[action], obj, df->dwObjSize);
+
+ This->action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
+ This->action_map[action].offset = offset;
+ obj_df[action].dwOfs = offset;
+ offset += (type & DIDFT_BUTTON) ? 1 : 4;
+
+ action++;
+ }
+ }
+
+ IDirectInputDevice8_SetDataFormat(iface, &data_format);
+
+ HeapFree(GetProcessHeap(), 0, obj_df);
+
+ /* Set the device properties according to the action format */
+ dpr.diph.dwSize = sizeof(DIPROPRANGE);
+ dpr.lMin = lpdiaf->lAxisMin;
+ dpr.lMax = lpdiaf->lAxisMax;
+ dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ dpr.diph.dwHow = DIPH_DEVICE;
+ IDirectInputDevice8_SetProperty(iface, DIPROP_RANGE, &dpr.diph);
+
+ if (lpdiaf->dwBufferSize > 0)
+ {
+ dp.diph.dwSize = sizeof(DIPROPDWORD);
+ dp.dwData = lpdiaf->dwBufferSize;
+ dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ dp.diph.dwHow = DIPH_DEVICE;
+ IDirectInputDevice8_SetProperty(iface, DIPROP_BUFFERSIZE, &dp.diph);
+ }
+
+ return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
+}
+
/******************************************************************************
* queue_event - add new event to the ring queue
*/
@@ -1486,31 +1567,12 @@ HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W ifa
}
HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
- LPDIACTIONFORMATW lpdiaf,
- LPCWSTR lpszUserName,
- DWORD dwFlags)
+ LPDIACTIONFORMATW lpdiaf,
+ LPCWSTR lpszUserName,
+ DWORD dwFlags)
{
- DIPROPDWORD dp;
- DIPROPRANGE dpr;
-
FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
- dpr.diph.dwSize = sizeof(DIPROPRANGE);
- dpr.lMin = lpdiaf->lAxisMin;
- dpr.lMax = lpdiaf->lAxisMax;
- dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
- dpr.diph.dwHow = DIPH_DEVICE;
- IDirectInputDevice8_SetProperty(iface, DIPROP_RANGE, &dpr.diph);
-
- if (lpdiaf->dwBufferSize > 0)
- {
- dp.diph.dwSize = sizeof(DIPROPDWORD);
- dp.dwData = lpdiaf->dwBufferSize;
- dp.diph.dwHeaderSize = sizeof(DIPROPHEADER);
- dp.diph.dwHow = DIPH_DEVICE;
- IDirectInputDevice8_SetProperty(iface, DIPROP_BUFFERSIZE, &dp.diph);
- }
-
return DI_OK;
}
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h
index 9b7b370..347c642 100644
--- a/dlls/dinput/device_private.h
+++ b/dlls/dinput/device_private.h
@@ -128,6 +128,7 @@ extern DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic)
extern LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD type) DECLSPEC_HIDDEN;
extern HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN;
+extern HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN;
/* And the stubs */
extern HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface) DECLSPEC_HIDDEN;
diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c
index e3babc6..c6aa80b 100644
--- a/dlls/dinput/joystick.c
+++ b/dlls/dinput/joystick.c
@@ -503,66 +503,10 @@ HRESULT WINAPI JoystickWGenericImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
DWORD dwFlags)
{
JoystickGenericImpl *This = impl_from_IDirectInputDevice8W(iface);
- DIDATAFORMAT data_format;
- DIOBJECTDATAFORMAT *obj_df = NULL;
- int i, action = 0, num_actions = 0;
- unsigned int offset = 0;
FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
- if (This->base.acquired) return DIERR_ACQUIRED;
-
- data_format.dwSize = sizeof(data_format);
- data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
- data_format.dwFlags = DIDF_RELAXIS;
- data_format.dwDataSize = lpdiaf->dwDataSize;
-
- /* count the actions */
- for (i=0; i < lpdiaf->dwNumActions; i++)
- if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
- num_actions++;
-
- if (num_actions == 0) return DI_NOEFFECT;
-
- This->base.num_actions = num_actions;
-
- /* Construct the dataformat and actionmap */
- obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
- data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
- data_format.dwNumObjs = num_actions;
-
- This->base.action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
-
- for (i = 0; i < lpdiaf->dwNumActions; i++)
- {
- if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
- {
- LPDIDATAFORMAT df = This->base.data_format.wine_df;
- DWORD inst = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
- DWORD type = DIDFT_GETTYPE(lpdiaf->rgoAction[i].dwObjID);
- LPDIOBJECTDATAFORMAT obj;
-
- if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON;
- if (type == DIDFT_RELAXIS) type = DIDFT_AXIS;
-
- obj = dataformat_to_odf_by_type(df, inst, type);
-
- memcpy(&obj_df[action], obj, df->dwObjSize);
-
- This->base.action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
- This->base.action_map[action].offset = offset;
- obj_df[action].dwOfs = offset;
- offset += (type & DIDFT_BUTTON) ? 1 : 4;
-
- action++;
- }
- }
-
- IDirectInputDevice8_SetDataFormat(iface, &data_format);
-
- HeapFree(GetProcessHeap(), 0, obj_df);
-
- return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
+ return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, This->base.data_format.wine_df);
}
HRESULT WINAPI JoystickAGenericImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 1f766fc..cade73f 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -559,53 +559,9 @@ static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
LPCWSTR lpszUserName,
DWORD dwFlags)
{
- SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface);
- DIDATAFORMAT data_format;
- DIOBJECTDATAFORMAT *obj_df = NULL;
- int i, action = 0, num_actions = 0;
-
- if (This->base.acquired) return DIERR_ACQUIRED;
-
- data_format.dwSize = sizeof(data_format);
- data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
- data_format.dwFlags = DIDF_ABSAXIS;
- data_format.dwDataSize = lpdiaf->dwDataSize;
-
- /* count the actions */
- for (i=0; i < lpdiaf->dwNumActions; i++)
- if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
- num_actions++;
-
- if (num_actions == 0) return DI_NOEFFECT;
-
- This->base.num_actions = num_actions;
-
- /* Construct the dataformat and actionmap */
- obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
- data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
- data_format.dwNumObjs = num_actions;
-
- This->base.action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
-
- for (i = 0; i < lpdiaf->dwNumActions; i++)
- {
- if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
- {
- int instance = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
- memcpy(&obj_df[action], &c_dfDIKeyboard.rgodf[instance], c_dfDIKeyboard.dwObjSize);
-
- This->base.action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
- This->base.action_map[action].offset = action;
- obj_df[action].dwOfs = action;
- action++;
- }
- }
-
- IDirectInputDevice8_SetDataFormat(iface, &data_format);
-
- HeapFree(GetProcessHeap(), 0, obj_df);
+ FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
- return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
+ return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIKeyboard);
}
static HRESULT WINAPI SysKeyboardAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index f42cdb5..c362c3d 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -808,57 +808,9 @@ static HRESULT WINAPI SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
LPCWSTR lpszUserName,
DWORD dwFlags)
{
- SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
- DIDATAFORMAT data_format;
- DIOBJECTDATAFORMAT *obj_df = NULL;
- int i, action = 0, num_actions = 0;
- unsigned int offset = 0;
-
- if (This->base.acquired) return DIERR_ACQUIRED;
-
- /* count the actions */
- for (i=0; i < lpdiaf->dwNumActions; i++)
- if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
- num_actions++;
-
- if (num_actions == 0) return DI_NOEFFECT;
-
- data_format.dwSize = sizeof(data_format);
- data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);
- data_format.dwFlags = DIDF_ABSAXIS;
- data_format.dwDataSize = lpdiaf->dwDataSize;
-
- This->base.num_actions = num_actions;
-
- /* Constructing the dataformat and actionmap */
- obj_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DIOBJECTDATAFORMAT)*num_actions);
- data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
- data_format.dwNumObjs = num_actions;
-
- This->base.action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
-
- for (i = 0; i < lpdiaf->dwNumActions; i++)
- {
-
- if (IsEqualGUID(&This->base.guid, &lpdiaf->rgoAction[i].guidInstance))
- {
- int instance = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID);
- memcpy(&obj_df[action], &c_dfDIMouse.rgodf[instance], c_dfDIMouse.dwObjSize);
-
- This->base.action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData;
- This->base.action_map[action].offset = offset;
- obj_df[action].dwOfs = offset;
- offset += (obj_df[action].dwType & DIDFT_BUTTON) ? 1 : 4;
-
- action++;
- }
- }
-
- IDirectInputDevice8_SetDataFormat(iface, &data_format);
-
- HeapFree(GetProcessHeap(), 0, obj_df);
+ FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
- return IDirectInputDevice8WImpl_SetActionMap(iface, lpdiaf, lpszUserName, dwFlags);
+ return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIMouse2);
}
static HRESULT WINAPI SysMouseAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
--
1.7.0.4
From cb7966a2c7030d1523edbffd5bf9854e232221a9 Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <[email protected]>
Date: Thu, 18 Aug 2011 01:25:51 -0300
Subject: dinput8/tests: Moved EnumDevicesBySemantics specific tests to dinput.c and added a couple more
---
dlls/dinput8/tests/device.c | 61 ------------------
dlls/dinput8/tests/dinput.c | 149 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 149 insertions(+), 61 deletions(-)
diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c
index 30c702f..63bf55a 100644
--- a/dlls/dinput8/tests/device.c
+++ b/dlls/dinput8/tests/device.c
@@ -205,29 +205,6 @@ static BOOL CALLBACK enumeration_callback(
return DIENUM_CONTINUE;
}
-/* A simpler callback function used to count and check
- the enumeration of devices.
-*/
-static BOOL CALLBACK counting_callback(
- LPCDIDEVICEINSTANCE lpddi,
- LPDIRECTINPUTDEVICE8 lpdid,
- DWORD dwFlags,
- DWORD dwRemaining,
- LPVOID pvRef)
-{
- struct enum_data *data = pvRef;
- if (!data) return DIENUM_CONTINUE;
-
- data->ndevices++;
- if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard))
- data->keyboard = lpdid;
-
- if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysMouse))
- data->mouse = lpdid;
-
- return DIENUM_CONTINUE;
-}
-
static void test_action_mapping(void)
{
HRESULT hr;
@@ -235,7 +212,6 @@ static void test_action_mapping(void)
LPDIRECTINPUT8 pDI = NULL;
DIACTIONFORMAT af;
struct enum_data data = {pDI, &af, NULL, NULL, 0};
- struct enum_data count = {pDI, &af, NULL, NULL, 0};
hr = CoCreateInstance(&CLSID_DirectInput8, 0, 1, &IID_IDirectInput8A, (LPVOID*)&pDI);
if (hr == DIERR_OLDDIRECTINPUTVERSION ||
@@ -267,42 +243,10 @@ static void test_action_mapping(void)
af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
af.dwBufferSize = 32;
- /* Test enumerating all attached and installed devices */
- count.keyboard = NULL;
- count.mouse = NULL;
- count.ndevices = 0;
- hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_ATTACHEDONLY);
- ok (count.ndevices > 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr);
- ok (count.keyboard != NULL, "EnumDevicesBySemantics should enumerate the keyboard\n");
- ok (count.mouse != NULL, "EnumDevicesBySemantics should enumerate the mouse\n");
-
- /* Enumerate Force feedback devices. We should get no mouse nor keyboard */
- count.keyboard = NULL;
- count.mouse = NULL;
- hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_FORCEFEEDBACK);
- ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
- ok (count.keyboard == NULL, "Keyboard should not be enumerated when asking for forcefeedback\n");
- ok (count.mouse == NULL, "Mouse should not be enumerated when asking for forcefeedback\n");
-
- /* Enumerate available devices. That is devices with not owned by any user.
- Before setting the action map for all devices we still have them available.
- */
- count.ndevices = 0;
- hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_AVAILABLEDEVICES);
- ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
- ok (count.ndevices > 0, "There should be devices available before action mapping available=%d\n", count.ndevices);
-
/* This enumeration builds and sets the action map for all devices */
hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
- /* After a successful action mapping we should have no devices available */
- count.ndevices = 0;
- hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, counting_callback, &count, DIEDBSFL_AVAILABLEDEVICES);
- ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
- todo_wine ok (count.ndevices == 0, "No device should be available after action mapping available=%d\n", count.ndevices);
-
- /* Use the devices we collect for some tests */
if (data.keyboard != NULL)
{
/* Test keyboard BuildActionMap */
@@ -333,11 +277,6 @@ static void test_action_mapping(void)
test_device_input(data.mouse, INPUT_MOUSE, MOUSEEVENTF_LEFTDOWN, 3);
}
-
- /* The call fails with a zeroed GUID */
- memset(&af.guidActionMap, 0, sizeof(GUID));
- hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, 0, 0);
- todo_wine ok(FAILED(hr), "EnumDevicesBySemantics succeeded with invalid GUID hr=%08x\n", hr);
}
START_TEST(device)
diff --git a/dlls/dinput8/tests/dinput.c b/dlls/dinput8/tests/dinput.c
index 88c4c5a..7251939 100644
--- a/dlls/dinput8/tests/dinput.c
+++ b/dlls/dinput8/tests/dinput.c
@@ -421,6 +421,154 @@ static void test_EnumDevices(void)
IDirectInput8_Release(pDI);
}
+struct enum_semantics_test
+{
+ unsigned int device_count;
+ BOOL mouse;
+ BOOL keyboard;
+ LPDIACTIONFORMAT lpdiaf;
+ const char* username;
+};
+
+static DIACTION actionMapping[]=
+{
+ /* axis */
+ { 0, 0x01008A01 /* DIAXIS_DRIVINGR_STEER */, 0, { "Steer" } },
+ /* button */
+ { 1, 0x01000C01 /* DIBUTTON_DRIVINGR_SHIFTUP */, 0, { "Upshift" } },
+ /* keyboard key */
+ { 2, DIKEYBOARD_SPACE, 0, { "Missile" } },
+ /* mouse button */
+ { 3, DIMOUSE_BUTTON0, 0, { "Select" } },
+ /* mouse axis */
+ { 4, DIMOUSE_YAXIS, 0, { "Y Axis" } }
+};
+
+static BOOL CALLBACK enum_semantics_callback(LPCDIDEVICEINSTANCE lpddi, IDirectInputDevice8A *lpdid, DWORD dwFlags, DWORD dwRemaining, void *context)
+{
+ struct enum_semantics_test *data = context;
+
+ if (context == NULL) return DIENUM_STOP;
+
+ data->device_count++;
+
+ if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard)) data->keyboard = TRUE;
+
+ if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysMouse)) data->mouse = TRUE;
+
+ return DIENUM_CONTINUE;
+}
+
+static BOOL CALLBACK set_action_map_callback(LPCDIDEVICEINSTANCE lpddi, IDirectInputDevice8A *lpdid, DWORD dwFlags, DWORD dwRemaining, void *context)
+{
+ HRESULT hr;
+ struct enum_semantics_test *data = context;
+
+ /* Building and setting an action map */
+ /* It should not use any pre-stored mappings so we use DIDBAM_INITIALIZE */
+ hr = IDirectInputDevice8_BuildActionMap(lpdid, data->lpdiaf, NULL, DIDBAM_INITIALIZE);
+ ok (SUCCEEDED(hr), "BuildActionMap failed hr=%08x\n", hr);
+
+ hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, data->username, 0);
+ ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
+
+ return DIENUM_CONTINUE;
+}
+
+static void test_EnumDevicesBySemantics(void)
+{
+ IDirectInput8A *pDI;
+ HRESULT hr;
+ DIACTIONFORMATA diaf;
+ const GUID ACTION_MAPPING_GUID = { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
+ struct enum_semantics_test data = { 0, FALSE, FALSE, &diaf, NULL };
+ int device_total = 0;
+
+ hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput8A, (void **)&pDI, NULL);
+ if (FAILED(hr))
+ {
+ win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
+ return;
+ }
+
+ memset (&diaf, 0, sizeof(diaf));
+ diaf.dwSize = sizeof(diaf);
+ diaf.dwActionSize = sizeof(DIACTION);
+ diaf.dwNumActions = sizeof(actionMapping) / sizeof(actionMapping[0]);
+ diaf.dwDataSize = 4 * diaf.dwNumActions;
+ diaf.rgoAction = actionMapping;
+ diaf.guidActionMap = ACTION_MAPPING_GUID;
+ diaf.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
+ diaf.dwBufferSize = 32;
+
+ /* Test enumerating all attached and installed devices */
+ data.keyboard = FALSE;
+ data.mouse = FALSE;
+ data.device_count = 0;
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, enum_semantics_callback, &data, DIEDBSFL_ATTACHEDONLY);
+ ok (data.device_count > 0, "EnumDevicesBySemantics did not call the callback hr=%08x\n", hr);
+ ok (data.keyboard, "EnumDevicesBySemantics should enumerate the keyboard\n");
+ ok (data.mouse, "EnumDevicesBySemantics should enumerate the mouse\n");
+
+ /* Enumerate Force feedback devices. We should get no mouse nor keyboard */
+ data.keyboard = FALSE;
+ data.mouse = FALSE;
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, enum_semantics_callback, &data, DIEDBSFL_FORCEFEEDBACK);
+ ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
+ ok (!data.keyboard, "Keyboard should not be enumerated when asking for forcefeedback\n");
+ ok (!data.mouse, "Mouse should not be enumerated when asking for forcefeedback\n");
+
+ /* Enumerate available devices. That is devices not owned by any user.
+ Before setting the action map for all devices we still have them available. */
+ data.device_count = 0;
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, enum_semantics_callback, &data, DIEDBSFL_AVAILABLEDEVICES);
+ ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
+ ok (data.device_count > 0, "There should be devices available before action mapping available=%d\n", data.device_count);
+
+ /* Keep the device total */
+ device_total = data.device_count;
+
+ /* This enumeration builds and sets the action map for all devices with a NULL username */
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, set_action_map_callback, &data, DIEDBSFL_ATTACHEDONLY);
+ ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
+
+ /* After a successful action mapping we should have no devices available */
+ data.device_count = 0;
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, enum_semantics_callback, &data, DIEDBSFL_AVAILABLEDEVICES);
+ ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
+ todo_wine ok (data.device_count == 0, "No device should be available after action mapping available=%d\n", data.device_count);
+
+ /* Now we'll give all the devices to a specific user */
+ data.username = "Sh4d0w M4g3";
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, set_action_map_callback, &data, DIEDBSFL_ATTACHEDONLY);
+ ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
+
+ /* Testing with the default user */
+ data.device_count = 0;
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, enum_semantics_callback, &data, DIEDBSFL_THISUSER);
+ ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
+ todo_wine ok (data.device_count == 0, "This user should own no devices owned=%d\n", data.device_count);
+
+ /* Testing with another user */
+ data.device_count = 0;
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, "Ninja Brian", &diaf, enum_semantics_callback, &data, DIEDBSFL_THISUSER);
+ ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
+ todo_wine ok (data.device_count == 0, "This user should own no devices owned=%d\n", data.device_count);
+
+ /* Sh4d0w M4g3 has ownership of all devices */
+ data.device_count = 0;
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, "Sh4d0w M4g3", &diaf, enum_semantics_callback, &data, DIEDBSFL_THISUSER);
+ ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed hr=%08x\n", hr);
+ ok (data.device_count == device_total, "This user should own %d devices owned=%d\n", device_total, data.device_count);
+
+ /* The call fails with a zeroed GUID */
+ memset(&diaf.guidActionMap, 0, sizeof(GUID));
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &diaf, enum_semantics_callback, NULL, 0);
+ todo_wine ok(FAILED(hr), "EnumDevicesBySemantics succeeded with invalid GUID hr=%08x\n", hr);
+
+ IDirectInput8_Release(pDI);
+}
+
static void test_GetDeviceStatus(void)
{
IDirectInput8A *pDI;
@@ -529,6 +677,7 @@ START_TEST(dinput)
test_QueryInterface();
test_CreateDevice();
test_EnumDevices();
+ test_EnumDevicesBySemantics();
test_GetDeviceStatus();
test_RunControlPanel();
test_Initialize();
--
1.7.0.4
From 33a7b51ce3130431b9bbc7fffe8c0b01c4499bcd Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <[email protected]>
Date: Thu, 18 Aug 2011 03:05:08 -0300
Subject: dinput8/tests: Tests for DIPROP_USERNAME property
Makefile needs to link advapi32 for GetUserName
---
dlls/dinput8/tests/Makefile.in | 2 +-
dlls/dinput8/tests/device.c | 34 +++++++++++++++++++++++++++++++---
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/dlls/dinput8/tests/Makefile.in b/dlls/dinput8/tests/Makefile.in
index 7584858..fe87118 100644
--- a/dlls/dinput8/tests/Makefile.in
+++ b/dlls/dinput8/tests/Makefile.in
@@ -1,5 +1,5 @@
TESTDLL = dinput8.dll
-IMPORTS = dinput8 ole32 user32
+IMPORTS = dinput8 ole32 user32 advapi32
C_SRCS = \
device.c \
diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c
index 63bf55a..29ac1fb 100644
--- a/dlls/dinput8/tests/device.c
+++ b/dlls/dinput8/tests/device.c
@@ -31,6 +31,7 @@ struct enum_data {
LPDIACTIONFORMAT lpdiaf;
LPDIRECTINPUTDEVICE8 keyboard;
LPDIRECTINPUTDEVICE8 mouse;
+ const char* username;
int ndevices;
};
@@ -133,11 +134,24 @@ static BOOL CALLBACK enumeration_callback(
HRESULT hr;
DIPROPDWORD dp;
DIPROPRANGE dpr;
+ DIPROPSTRING dps;
+ WCHAR usernameW[MAX_PATH];
+ DWORD username_size = MAX_PATH;
struct enum_data *data = pvRef;
+
if (!data) return DIENUM_CONTINUE;
data->ndevices++;
+ /* Convert username to WCHAR */
+ if (data->username != NULL)
+ {
+ username_size = MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, 0);
+ MultiByteToWideChar(CP_ACP, 0, data->username, -1, usernameW, username_size);
+ }
+ else
+ GetUserNameW(usernameW, &username_size);
+
/* collect the mouse and keyboard */
if (IsEqualGUID(&lpddi->guidInstance, &GUID_SysKeyboard))
{
@@ -164,12 +178,21 @@ static BOOL CALLBACK enumeration_callback(
hr = IDirectInputDevice8_Acquire(lpdid);
ok (hr == DIERR_INVALIDPARAM, "Device was acquired before SetActionMap hr=%08x\n", hr);
- hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, NULL, 0);
+ hr = IDirectInputDevice8_SetActionMap(lpdid, data->lpdiaf, data->username, 0);
ok (SUCCEEDED(hr), "SetActionMap failed hr=%08x\n", hr);
/* Some joysticks may have no suitable actions and thus should not be tested */
if (hr == DI_NOEFFECT) return DIENUM_CONTINUE;
+ /* Test username after SetActionMap */
+ dps.diph.dwSize = sizeof(dps);
+ dps.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ dps.diph.dwHow = DIPH_DEVICE;
+
+ hr = IDirectInputDevice_GetProperty(lpdid, DIPROP_USERNAME, &dps.diph);
+ todo_wine ok (SUCCEEDED(hr), "GetProperty failed hr=%08x\n", hr);
+ todo_wine ok (!lstrcmpW(usernameW, dps.wsz), "Username not set correctly expected=%s, got=%s\n", wine_dbgstr_wn(usernameW, -1), wine_dbgstr_wn(dps.wsz,-1));
+
/* Test buffer size */
memset(&dp, 0, sizeof(dp));
dp.diph.dwSize = sizeof(dp);
@@ -211,7 +234,7 @@ static void test_action_mapping(void)
HINSTANCE hinst = GetModuleHandle(NULL);
LPDIRECTINPUT8 pDI = NULL;
DIACTIONFORMAT af;
- struct enum_data data = {pDI, &af, NULL, NULL, 0};
+ struct enum_data data = {pDI, &af, NULL, NULL, NULL, 0};
hr = CoCreateInstance(&CLSID_DirectInput8, 0, 1, &IID_IDirectInput8A, (LPVOID*)&pDI);
if (hr == DIERR_OLDDIRECTINPUTVERSION ||
@@ -244,7 +267,12 @@ static void test_action_mapping(void)
af.dwBufferSize = 32;
/* This enumeration builds and sets the action map for all devices */
- hr = IDirectInput8_EnumDevicesBySemantics(pDI, 0, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
+ ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
+
+ /* Repeat tests with a non NULL user */
+ data.username = "Ninja Brian";
+ hr = IDirectInput8_EnumDevicesBySemantics(pDI, NULL, &af, enumeration_callback, &data, DIEDBSFL_ATTACHEDONLY);
ok (SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n", hr);
if (data.keyboard != NULL)
--
1.7.0.4
From b0ab0de46c272fd9a286997186d743b3f9ede067 Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <[email protected]>
Date: Thu, 11 Aug 2011 18:33:01 -0300
Subject: dinput: Free previous action map in SetActionMap
---
dlls/dinput/device.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index d2de525..ead1052 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -674,6 +674,7 @@ HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, L
data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df;
data_format.dwNumObjs = num_actions;
+ HeapFree(GetProcessHeap(), 0, This->action_map);
This->action_map = HeapAlloc(GetProcessHeap(), 0, sizeof(ActionMap)*num_actions);
for (i = 0; i < lpdiaf->dwNumActions; i++)
--
1.7.0.4
From e841cdb19149f6e1449ac178acd9540ad9787d43 Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <[email protected]>
Date: Tue, 9 Aug 2011 23:56:41 -0300
Subject: dinput: Proper conversion of username parameters for Set and BuildActionMap
---
dlls/dinput/joystick.c | 24 ++++++++++++++++++++++--
dlls/dinput/keyboard.c | 24 ++++++++++++++++++++++--
dlls/dinput/mouse.c | 24 ++++++++++++++++++++++--
3 files changed, 66 insertions(+), 6 deletions(-)
diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c
index c6aa80b..cdded1b 100644
--- a/dlls/dinput/joystick.c
+++ b/dlls/dinput/joystick.c
@@ -485,14 +485,24 @@ HRESULT WINAPI JoystickAGenericImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
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);
- hr = JoystickWGenericImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, NULL, dwFlags);
+ 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;
}
@@ -517,13 +527,23 @@ HRESULT WINAPI JoystickAGenericImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
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);
- hr = JoystickWGenericImpl_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, NULL, dwFlags);
+ 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_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
+ HeapFree(GetProcessHeap(), 0, lpszUserNameW);
return hr;
}
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index cade73f..4de8692 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -542,14 +542,24 @@ static HRESULT WINAPI SysKeyboardAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A ifac
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);
- hr = SysKeyboardWImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, NULL, dwFlags);
+ 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;
}
@@ -572,13 +582,23 @@ static HRESULT WINAPI SysKeyboardAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
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);
- hr = SysKeyboardWImpl_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, NULL, dwFlags);
+ 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_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
+ HeapFree(GetProcessHeap(), 0, lpszUserNameW);
return hr;
}
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index c362c3d..011deb0 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -791,14 +791,24 @@ static HRESULT WINAPI SysMouseAImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
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);
- hr = SysMouseWImpl_BuildActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, NULL, dwFlags);
+ 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;
}
@@ -821,13 +831,23 @@ static HRESULT WINAPI SysMouseAImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
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);
- hr = SysMouseWImpl_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, NULL, dwFlags);
+ 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_SetActionMap(&This->base.IDirectInputDevice8W_iface, &diafW, lpszUserNameW, dwFlags);
HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
+ HeapFree(GetProcessHeap(), 0, lpszUserNameW);
return hr;
}
--
1.7.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment