Commit 0ba314eb authored by Andrew Eikum's avatar Andrew Eikum Committed by Alexandre Julliard

dinput: Enumerate devices past the first non-matching device.

parent 1ff63bb8
......@@ -370,17 +370,17 @@ static HRESULT WINAPI IDirectInputAImpl_EnumDevices(
for (i = 0; i < NB_DINPUT_DEVICES; i++) {
if (!dinput_devices[i]->enum_deviceA) continue;
for (j = 0, r = -1; r != 0; j++) {
for (j = 0, r = S_OK; SUCCEEDED(r); j++) {
devInstance.dwSize = sizeof(devInstance);
TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name);
if ((r = dinput_devices[i]->enum_deviceA(dwDevType, dwFlags, &devInstance, This->dwVersion, j))) {
r = dinput_devices[i]->enum_deviceA(dwDevType, dwFlags, &devInstance, This->dwVersion, j);
if (r == S_OK)
if (lpCallback(&devInstance,pvRef) == DIENUM_STOP)
return 0;
}
return S_OK;
}
}
return 0;
return S_OK;
}
/******************************************************************************
* IDirectInputW_EnumDevices
......@@ -392,7 +392,8 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
IDirectInputImpl *This = impl_from_IDirectInput7W( iface );
DIDEVICEINSTANCEW devInstance;
unsigned int i;
int j, r;
int j;
HRESULT r;
TRACE("(this=%p,0x%04x '%s',%p,%p,%04x)\n",
This, dwDevType, _dump_DIDEVTYPE_value(dwDevType),
......@@ -409,17 +410,17 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
for (i = 0; i < NB_DINPUT_DEVICES; i++) {
if (!dinput_devices[i]->enum_deviceW) continue;
for (j = 0, r = -1; r != 0; j++) {
for (j = 0, r = S_OK; SUCCEEDED(r); j++) {
devInstance.dwSize = sizeof(devInstance);
TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name);
if ((r = dinput_devices[i]->enum_deviceW(dwDevType, dwFlags, &devInstance, This->dwVersion, j))) {
r = dinput_devices[i]->enum_deviceW(dwDevType, dwFlags, &devInstance, This->dwVersion, j);
if (r == S_OK)
if (lpCallback(&devInstance,pvRef) == DIENUM_STOP)
return 0;
}
return S_OK;
}
}
return 0;
return S_OK;
}
static ULONG WINAPI IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface)
......@@ -908,18 +909,18 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics(
/* Enumerate all the joysticks */
for (i = 0; i < NB_DINPUT_DEVICES; i++)
{
BOOL enumSuccess;
HRESULT enumSuccess;
if (!dinput_devices[i]->enum_deviceA) continue;
for (j = 0, enumSuccess = -1; enumSuccess != 0; j++)
for (j = 0, enumSuccess = S_OK; SUCCEEDED(enumSuccess); j++)
{
TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name);
callbackFlags = diactionformat_priorityA(lpdiActionFormat, lpdiActionFormat->dwGenre);
/* Default behavior is to enumerate attached game controllers */
enumSuccess = dinput_devices[i]->enum_deviceA(DI8DEVCLASS_GAMECTRL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j);
if (enumSuccess)
if (enumSuccess == S_OK)
{
IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL);
......@@ -968,18 +969,18 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
/* Enumerate all the joysticks */
for (i = 0; i < NB_DINPUT_DEVICES; i++)
{
BOOL enumSuccess;
HRESULT enumSuccess;
if (!dinput_devices[i]->enum_deviceW) continue;
for (j = 0, enumSuccess = -1; enumSuccess != 0; j++)
for (j = 0, enumSuccess = S_OK; SUCCEEDED(enumSuccess); j++)
{
TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name);
callbackFlags = diactionformat_priorityW(lpdiActionFormat, lpdiActionFormat->dwGenre);
/* Default behavior is to enumerate attached game controllers */
enumSuccess = dinput_devices[i]->enum_deviceW(DI8DEVCLASS_GAMECTRL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j);
if (enumSuccess)
if (enumSuccess == S_OK)
{
IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL);
......@@ -1147,7 +1148,8 @@ static HRESULT WINAPI JoyConfig8Impl_GetConfig(IDirectInputJoyConfig8 *iface, UI
{
IDirectInputImpl *di = impl_from_IDirectInputJoyConfig8(iface);
UINT found = 0;
int i, j, r;
int i, j;
HRESULT r;
FIXME("(%p)->(%d, %p, 0x%08x): semi-stub!\n", iface, id, info, flags);
......@@ -1163,11 +1165,11 @@ static HRESULT WINAPI JoyConfig8Impl_GetConfig(IDirectInputJoyConfig8 *iface, UI
{
if (!dinput_devices[i]->enum_deviceA) continue;
for (j = 0, r = -1; r != 0; j++)
for (j = 0, r = S_OK; SUCCEEDED(r); j++)
{
DIDEVICEINSTANCEA dev;
dev.dwSize = sizeof(dev);
if ((r = dinput_devices[i]->enum_deviceA(DI8DEVCLASS_GAMECTRL, 0, &dev, di->dwVersion, j)))
if ((r = dinput_devices[i]->enum_deviceA(DI8DEVCLASS_GAMECTRL, 0, &dev, di->dwVersion, j)) == S_OK)
{
/* Only take into account the chosen id */
if (found == id)
......
......@@ -51,8 +51,8 @@ struct IDirectInputImpl
/* Function called by all devices that Wine supports */
struct dinput_device {
const char *name;
BOOL (*enum_deviceA)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id);
BOOL (*enum_deviceW)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id);
HRESULT (*enum_deviceA)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id);
HRESULT (*enum_deviceW)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id);
HRESULT (*create_device)(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode);
};
......
......@@ -220,15 +220,15 @@ static INT find_joystick_devices(void)
return joystick_devices_count;
}
static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
static HRESULT joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
{
int fd = -1;
if (id >= find_joystick_devices()) return FALSE;
if (id >= find_joystick_devices()) return E_FAIL;
if (dwFlags & DIEDFL_FORCEFEEDBACK) {
WARN("force feedback not supported\n");
return FALSE;
return S_FALSE;
}
if ((dwDevType == 0) ||
......@@ -238,7 +238,7 @@ static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTAN
if ((fd = open(joystick_devices[id].device, O_RDONLY)) < 0)
{
WARN("open(%s, O_RDONLY) failed: %s\n", joystick_devices[id].name, strerror(errno));
return FALSE;
return S_FALSE;
}
/* Return joystick */
......@@ -257,21 +257,21 @@ static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTAN
lpddi->guidFFDriver = GUID_NULL;
close(fd);
TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, lpddi->tszProductName);
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
{
int fd = -1;
if (id >= find_joystick_devices()) return FALSE;
if (id >= find_joystick_devices()) return E_FAIL;
if (dwFlags & DIEDFL_FORCEFEEDBACK) {
WARN("force feedback not supported\n");
return FALSE;
return S_FALSE;
}
if ((dwDevType == 0) ||
......@@ -281,7 +281,7 @@ static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTAN
if ((fd = open(joystick_devices[id].device, O_RDONLY)) < 0)
{
WARN("open(%s,O_RDONLY) failed: %s\n", joystick_devices[id].device, strerror(errno));
return FALSE;
return S_FALSE;
}
/* Return joystick */
......@@ -299,10 +299,10 @@ static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTAN
lpddi->guidFFDriver = GUID_NULL;
close(fd);
TRACE("Enumerating the linux Joystick device: %s (%s)\n", joystick_devices[id].device, joystick_devices[id].name);
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
......
......@@ -363,54 +363,54 @@ static void fill_joystick_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD ver
MultiByteToWideChar(CP_ACP, 0, joydevs[id].name, -1, lpddi->tszProductName, MAX_PATH);
}
static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
static HRESULT joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
{
find_joydevs();
if (id >= have_joydevs) {
return FALSE;
return E_FAIL;
}
if (!((dwDevType == 0) ||
((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
(((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
return FALSE;
return S_FALSE;
#ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
if (dwFlags & DIEDFL_FORCEFEEDBACK)
return FALSE;
return S_FALSE;
#endif
if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
fill_joystick_dideviceinstanceA(lpddi, version, id);
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
{
find_joydevs();
if (id >= have_joydevs) {
return FALSE;
return E_FAIL;
}
if (!((dwDevType == 0) ||
((dwDevType == DIDEVTYPE_JOYSTICK) && (version > 0x0300 && version < 0x0800)) ||
(((dwDevType == DI8DEVCLASS_GAMECTRL) || (dwDevType == DI8DEVTYPE_JOYSTICK)) && (version >= 0x0800))))
return FALSE;
return S_FALSE;
#ifndef HAVE_STRUCT_FF_EFFECT_DIRECTION
if (dwFlags & DIEDFL_FORCEFEEDBACK)
return FALSE;
return S_FALSE;
#endif
if (!(dwFlags & DIEDFL_FORCEFEEDBACK) || joydevs[id].has_ff) {
fill_joystick_dideviceinstanceW(lpddi, version, id);
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsigned short index)
......
......@@ -651,13 +651,13 @@ static INT find_joystick_devices(void)
return joystick_devices_count;
}
static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
static HRESULT joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
{
if (id >= find_joystick_devices()) return FALSE;
if (id >= find_joystick_devices()) return E_FAIL;
if (dwFlags & DIEDFL_FORCEFEEDBACK) {
WARN("force feedback not supported\n");
return FALSE;
return S_FALSE;
}
if ((dwDevType == 0) ||
......@@ -679,22 +679,22 @@ static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTAN
get_osx_device_name(id, lpddi->tszProductName, MAX_PATH);
lpddi->guidFFDriver = GUID_NULL;
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
{
char name[MAX_PATH];
char friendly[32];
if (id >= find_joystick_devices()) return FALSE;
if (id >= find_joystick_devices()) return E_FAIL;
if (dwFlags & DIEDFL_FORCEFEEDBACK) {
WARN("force feedback not supported\n");
return FALSE;
return S_FALSE;
}
if ((dwDevType == 0) ||
......@@ -716,10 +716,10 @@ static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTAN
MultiByteToWideChar(CP_ACP, 0, name, -1, lpddi->tszProductName, MAX_PATH);
lpddi->guidFFDriver = GUID_NULL;
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
......
......@@ -184,10 +184,10 @@ static void fill_keyboard_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD ver
memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
}
static BOOL keyboarddev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
static HRESULT keyboarddev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
{
if (id != 0)
return FALSE;
return E_FAIL;
if ((dwDevType == 0) ||
((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) ||
......@@ -196,16 +196,16 @@ static BOOL keyboarddev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEI
fill_keyboard_dideviceinstanceA(lpddi, version);
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static BOOL keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
static HRESULT keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
{
if (id != 0)
return FALSE;
return E_FAIL;
if ((dwDevType == 0) ||
((dwDevType == DIDEVTYPE_KEYBOARD) && (version < 0x0800)) ||
......@@ -214,10 +214,10 @@ static BOOL keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEI
fill_keyboard_dideviceinstanceW(lpddi, version);
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
......
......@@ -159,10 +159,10 @@ static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD versio
memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
}
static BOOL mousedev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
static HRESULT mousedev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
{
if (id != 0)
return FALSE;
return E_FAIL;
if ((dwDevType == 0) ||
((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
......@@ -171,16 +171,16 @@ static BOOL mousedev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINST
fill_mouse_dideviceinstanceA(lpddi, version);
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static BOOL mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
static HRESULT mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
{
if (id != 0)
return FALSE;
return E_FAIL;
if ((dwDevType == 0) ||
((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
......@@ -189,10 +189,10 @@ static BOOL mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINST
fill_mouse_dideviceinstanceW(lpddi, version);
return TRUE;
return S_OK;
}
return FALSE;
return S_FALSE;
}
static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
......
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