Skip to content

Instantly share code, notes, and snippets.

@lfzawacki
Created June 20, 2011 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lfzawacki/1035519 to your computer and use it in GitHub Desktop.
Save lfzawacki/1035519 to your computer and use it in GitHub Desktop.
From 14134e4fad0d549b8cdda34d411174c084076dc5 Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
Date: Wed, 8 Jun 2011 23:49:34 -0300
Subject: dinput: EnumDevicesBySemantics enumerating system keyboard and mouse
---
dlls/dinput/dinput_main.c | 98 +++++++++++++++++++++++++++++++++++++++++---
1 files changed, 91 insertions(+), 7 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index d3727bc..25d7567 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -254,6 +254,60 @@ void _dump_diactionformatA(LPDIACTIONFORMATA lpdiActionFormat) {
}
}
+void _copy_diactionformatAtoW(LPDIACTIONFORMATW to, LPDIACTIONFORMATA from)
+{
+ int i;
+
+ to->dwSize = sizeof(DIACTIONFORMATW);
+ to->dwActionSize = sizeof(DIACTIONW);
+ to->dwDataSize = from->dwDataSize;
+ to->dwNumActions = from->dwNumActions;
+ to->guidActionMap = from->guidActionMap;
+ to->dwGenre = from->dwGenre;
+ to->dwBufferSize = from->dwBufferSize;
+ to->lAxisMin = from->lAxisMin;
+ to->lAxisMax = from->lAxisMax;
+ to->dwCRC = from->dwCRC;
+ to->ftTimeStamp = from->ftTimeStamp;
+
+ for (i=0; i < to->dwNumActions; i++)
+ {
+ to->rgoAction[i].uAppData = from->rgoAction[i].uAppData;
+ to->rgoAction[i].dwSemantic = from->rgoAction[i].dwSemantic;
+ to->rgoAction[i].dwFlags = from->rgoAction[i].dwFlags;
+ to->rgoAction[i].guidInstance = from->rgoAction[i].guidInstance;
+ to->rgoAction[i].dwObjID = from->rgoAction[i].dwObjID;
+ to->rgoAction[i].dwHow = from->rgoAction[i].dwHow;
+ }
+}
+
+void _copy_diactionformatWtoA(LPDIACTIONFORMATA to, LPDIACTIONFORMATW from)
+{
+ int i;
+
+ to->dwSize = sizeof(DIACTIONFORMATA);
+ to->dwActionSize = sizeof(DIACTIONA);
+ to->dwDataSize = from->dwDataSize;
+ to->dwNumActions = from->dwNumActions;
+ to->guidActionMap = from->guidActionMap;
+ to->dwGenre = from->dwGenre;
+ to->dwBufferSize = from->dwBufferSize;
+ to->lAxisMin = from->lAxisMin;
+ to->lAxisMax = from->lAxisMax;
+ to->dwCRC = from->dwCRC;
+ to->ftTimeStamp = from->ftTimeStamp;
+
+ for (i=0; i < to->dwNumActions; i++)
+ {
+ to->rgoAction[i].uAppData = from->rgoAction[i].uAppData;
+ to->rgoAction[i].dwSemantic = from->rgoAction[i].dwSemantic;
+ to->rgoAction[i].dwFlags = from->rgoAction[i].dwFlags;
+ to->rgoAction[i].guidInstance = from->rgoAction[i].guidInstance;
+ to->rgoAction[i].dwObjID = from->rgoAction[i].dwObjID;
+ to->rgoAction[i].dwHow = from->rgoAction[i].dwHow;
+ }
+}
+
/******************************************************************************
* IDirectInputA_EnumDevices
*/
@@ -681,9 +735,9 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics(
)
{
IDirectInputImpl *This = impl_from_IDirectInput8A( iface );
+ DIACTIONFORMATW lpdiafW;
+ HRESULT hr;
- FIXME("(this=%p,%s,%p,%p,%p,%04x): stub\n", This, ptszUserName, lpdiActionFormat,
- lpCallback, pvRef, dwFlags);
#define X(x) if (dwFlags & x) FIXME("\tdwFlags |= "#x"\n");
X(DIEDBSFL_ATTACHEDONLY)
X(DIEDBSFL_THISUSER)
@@ -695,7 +749,18 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics(
_dump_diactionformatA(lpdiActionFormat);
- return DI_OK;
+ lpdiafW.rgoAction = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
+ sizeof(DIACTIONW)*lpdiActionFormat->dwNumActions);
+ _copy_diactionformatAtoW(&lpdiafW,lpdiActionFormat);
+
+ hr = IDirectInput8_EnumDevicesBySemantics( &This->IDirectInput8W_iface,
+ NULL, &lpdiafW, (LPDIENUMDEVICESBYSEMANTICSCBW) lpCallback, pvRef, dwFlags);
+
+ _copy_diactionformatWtoA(lpdiActionFormat, &lpdiafW);
+
+ HeapFree( GetProcessHeap(), 0, lpdiafW.rgoAction);
+
+ return hr;
}
static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
@@ -704,11 +769,30 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
LPVOID pvRef, DWORD dwFlags
)
{
- IDirectInputImpl *This = impl_from_IDirectInput8W( iface );
+ IDirectInputImpl *This = impl_from_IDirectInput8W( iface );
+ DIDEVICEINSTANCEW didevi;
+ LPDIRECTINPUTDEVICE8W lpdid;
+ BOOL ret; /* for the callback return */
+ DWORD callbackFlags = 0;
- FIXME("(this=%p,%s,%p,%p,%p,%04x): stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat,
- lpCallback, pvRef, dwFlags);
- return 0;
+ FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat,
+ lpCallback, pvRef, dwFlags);
+
+ didevi.dwSize = sizeof(didevi);
+
+ /* enum the keyboard first */
+ IDirectInput_CreateDevice(iface, &GUID_SysKeyboard, &lpdid, NULL);
+ IDirectInputDevice_GetDeviceInfo(lpdid, &didevi);
+ ret = lpCallback(&didevi, lpdid, callbackFlags , 1, pvRef);
+
+ if (ret == DIENUM_STOP) return DI_OK;
+
+ /* and then the mouse */
+ IDirectInput_CreateDevice(iface, &GUID_SysMouse, &lpdid, NULL);
+ IDirectInputDevice_GetDeviceInfo(lpdid, &didevi);
+ ret = lpCallback(&didevi, lpdid, callbackFlags , 0, pvRef);
+
+ return DI_OK;
}
static HRESULT WINAPI IDirectInput8AImpl_ConfigureDevices(
--
1.7.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment