Fix SetProperty error returned.

Add EnumDevice joystick version check.
Test multiple versions.
This commit is contained in:
Robert Reif 2005-05-13 13:57:17 +00:00 committed by Alexandre Julliard
parent 5037202554
commit 0f60464b95
4 changed files with 57 additions and 22 deletions

View File

@ -95,6 +95,7 @@ HRESULT WINAPI DirectInputCreateEx(
This->lpVtbl = &ddi7avt; This->lpVtbl = &ddi7avt;
This->ref = 1; This->ref = 1;
This->version = 1; This->version = 1;
This->dwVersion = dwVersion;
*ppDI = This; *ppDI = This;
return DI_OK; return DI_OK;
@ -107,6 +108,7 @@ HRESULT WINAPI DirectInputCreateEx(
This->lpVtbl = &ddi7wvt; This->lpVtbl = &ddi7wvt;
This->ref = 1; This->ref = 1;
This->version = 1; This->version = 1;
This->dwVersion = dwVersion;
*ppDI = This; *ppDI = This;
return DI_OK; return DI_OK;
@ -117,6 +119,7 @@ HRESULT WINAPI DirectInputCreateEx(
This->lpVtbl = &ddi8avt; This->lpVtbl = &ddi8avt;
This->ref = 1; This->ref = 1;
This->version = 8; This->version = 8;
This->dwVersion = dwVersion;
*ppDI = This; *ppDI = This;
return DI_OK; return DI_OK;
@ -127,6 +130,7 @@ HRESULT WINAPI DirectInputCreateEx(
This->lpVtbl = &ddi8wvt; This->lpVtbl = &ddi8wvt;
This->ref = 1; This->ref = 1;
This->version = 8; This->version = 8;
This->dwVersion = dwVersion;
*ppDI = This; *ppDI = This;
return DI_OK; return DI_OK;
@ -145,6 +149,7 @@ HRESULT WINAPI DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPU
This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl)); This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
This->lpVtbl = &ddi7avt; This->lpVtbl = &ddi7avt;
This->ref = 1; This->ref = 1;
This->dwVersion = dwVersion;
if (dwVersion >= 0x0800) { if (dwVersion >= 0x0800) {
This->version = 8; This->version = 8;
} else { } else {
@ -166,6 +171,7 @@ HRESULT WINAPI DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPU
This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl)); This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
This->lpVtbl = &ddi7wvt; This->lpVtbl = &ddi7wvt;
This->ref = 1; This->ref = 1;
This->dwVersion = dwVersion;
if (dwVersion >= 0x0800) { if (dwVersion >= 0x0800) {
This->version = 8; This->version = 8;
} else { } else {
@ -227,7 +233,11 @@ static HRESULT WINAPI IDirectInputAImpl_EnumDevices(
This, dwDevType, _dump_DIDEVTYPE_value(dwDevType), This, dwDevType, _dump_DIDEVTYPE_value(dwDevType),
lpCallback, pvRef, dwFlags); lpCallback, pvRef, dwFlags);
TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n"); TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
/* joysticks are not supported in version 0x0300 */
if ((dwDevType == DIDEVTYPE_JOYSTICK) && (This->dwVersion <= 0x0300))
return E_INVALIDARG;
for (i = 0; i < NB_DINPUT_DEVICES; i++) { for (i = 0; i < NB_DINPUT_DEVICES; i++) {
if (!dinput_devices[i]->enum_deviceA) continue; if (!dinput_devices[i]->enum_deviceA) continue;
for (j = 0, r = -1; r != 0; j++) { for (j = 0, r = -1; r != 0; j++) {
@ -257,7 +267,11 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
This, dwDevType, _dump_DIDEVTYPE_value(dwDevType), This, dwDevType, _dump_DIDEVTYPE_value(dwDevType),
lpCallback, pvRef, dwFlags); lpCallback, pvRef, dwFlags);
TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n"); TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
/* joysticks are not supported in version 0x0300 */
if ((dwDevType == DIDEVTYPE_JOYSTICK) && (This->dwVersion <= 0x0300))
return E_INVALIDARG;
for (i = 0; i < NB_DINPUT_DEVICES; i++) { for (i = 0; i < NB_DINPUT_DEVICES; i++) {
if (!dinput_devices[i]->enum_deviceW) continue; if (!dinput_devices[i]->enum_deviceW) continue;
for (j = 0, r = -1; r != 0; j++) { for (j = 0, r = -1; r != 0; j++) {

View File

@ -36,6 +36,7 @@ struct IDirectInputImpl
DWORD evsequence; DWORD evsequence;
int version; int version;
DWORD dwVersion;
}; };
/* Function called by all devices that Wine supports */ /* Function called by all devices that Wine supports */

View File

@ -1125,7 +1125,7 @@ static HRESULT WINAPI JoystickAImpl_SetProperty(
if (ph == NULL) { if (ph == NULL) {
WARN("invalid pointer\n"); WARN("invalid pointer\n");
return E_POINTER; return E_INVALIDARG;
} }
if (TRACE_ON(dinput)) if (TRACE_ON(dinput))

View File

@ -35,6 +35,11 @@
#define numObjects(x) (sizeof(x) / sizeof(x[0])) #define numObjects(x) (sizeof(x) / sizeof(x[0]))
typedef struct tagUserData {
LPDIRECTINPUT pDI;
DWORD version;
} UserData;
static const DIOBJECTDATAFORMAT dfDIJoystickTest[] = { static const DIOBJECTDATAFORMAT dfDIJoystickTest[] = {
{ &GUID_XAxis,DIJOFS_X,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, { &GUID_XAxis,DIJOFS_X,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
{ &GUID_YAxis,DIJOFS_Y,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0}, { &GUID_YAxis,DIJOFS_Y,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
@ -103,8 +108,8 @@ static BOOL CALLBACK EnumAxes(
diprg.lMax = +1000; diprg.lMax = +1000;
hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, NULL); hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, NULL);
ok(hr==E_POINTER,"IDirectInputDevice_SetProperty() should have returned " ok(hr==E_INVALIDARG,"IDirectInputDevice_SetProperty() should have returned "
"E_POINTER, returned: %s\n", DXGetErrorString8(hr)); "E_INVALIDARG, returned: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph); hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph);
ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %s\n", DXGetErrorString8(hr)); ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %s\n", DXGetErrorString8(hr));
@ -123,7 +128,7 @@ static BOOL CALLBACK EnumJoysticks(
LPVOID pvRef) LPVOID pvRef)
{ {
HRESULT hr; HRESULT hr;
LPDIRECTINPUT pDI = (LPDIRECTINPUT)pvRef; UserData * data = (UserData *)pvRef;
LPDIRECTINPUTDEVICE pJoystick; LPDIRECTINPUTDEVICE pJoystick;
DIDATAFORMAT format; DIDATAFORMAT format;
DIDEVCAPS caps; DIDEVCAPS caps;
@ -132,19 +137,20 @@ static BOOL CALLBACK EnumJoysticks(
int i, count; int i, count;
ULONG ref; ULONG ref;
hr = IDirectInput_CreateDevice(pDI, &lpddi->guidInstance, NULL, NULL); hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, NULL, NULL);
ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned " ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
"E_POINTER, returned: %s\n", DXGetErrorString8(hr)); "E_POINTER, returned: %s\n", DXGetErrorString8(hr));
hr = IDirectInput_CreateDevice(pDI, NULL, &pJoystick, NULL); hr = IDirectInput_CreateDevice(data->pDI, NULL, &pJoystick, NULL);
ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned " ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
"E_POINTER, returned: %s\n", DXGetErrorString8(hr)); "E_POINTER, returned: %s\n", DXGetErrorString8(hr));
hr = IDirectInput_CreateDevice(pDI, NULL, NULL, NULL); hr = IDirectInput_CreateDevice(data->pDI, NULL, NULL, NULL);
ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned " ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
"E_POINTER, returned: %s\n", DXGetErrorString8(hr)); "E_POINTER, returned: %s\n", DXGetErrorString8(hr));
hr = IDirectInput_CreateDevice(pDI, &lpddi->guidInstance, &pJoystick, NULL); hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance,
&pJoystick, NULL);
ok(hr==DI_OK,"IDirectInput_CreateDevice() failed: %s\n", ok(hr==DI_OK,"IDirectInput_CreateDevice() failed: %s\n",
DXGetErrorString8(hr)); DXGetErrorString8(hr));
if (hr!=DI_OK) if (hr!=DI_OK)
@ -260,22 +266,34 @@ DONE:
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
static void joystick_tests() static void joystick_tests(DWORD version)
{ {
HRESULT hr; HRESULT hr;
LPDIRECTINPUT pDI; LPDIRECTINPUT pDI;
ULONG ref; ULONG ref;
hr = DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &pDI, NULL); trace("-- Testing Direct Input Version 0x%04lx --\n", version);
ok(hr==DI_OK, "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr)); hr = DirectInputCreate(GetModuleHandle(NULL), version, &pDI, NULL);
if (hr!=DI_OK) ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION,
return; "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
if (hr==DI_OK && pDI!=0) {
hr = IDirectInput_EnumDevices(pDI, DIDEVTYPE_JOYSTICK, EnumJoysticks, pDI, DIEDFL_ALLDEVICES); UserData data;
ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %s\n", DXGetErrorString8(hr)); data.pDI = pDI;
data.version = version;
ref = IDirectInput_Release(pDI); hr = IDirectInput_EnumDevices(pDI, DIDEVTYPE_JOYSTICK, EnumJoysticks,
ok(ref==0,"IDirectInput_Release() reference count = %ld\n", ref); &data, DIEDFL_ALLDEVICES);
if (version == 0x0300) {
trace(" Joysticks Not Supported\n");
ok(hr==E_INVALIDARG,"IDirectInput_EnumDevices() should have "
"returned E_INVALIDARG, returned: %s\n", DXGetErrorString8(hr));
} else {
ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %s\n",
DXGetErrorString8(hr));
}
ref = IDirectInput_Release(pDI);
ok(ref==0,"IDirectInput_Release() reference count = %ld\n", ref);
} else if (hr==DIERR_OLDDIRECTINPUTVERSION)
trace(" Version Not Supported\n");
} }
START_TEST(joystick) START_TEST(joystick)
@ -284,7 +302,9 @@ START_TEST(joystick)
trace("DLL Version: %s\n", get_file_version("dinput.dll")); trace("DLL Version: %s\n", get_file_version("dinput.dll"));
joystick_tests(); joystick_tests(0x0700);
joystick_tests(0x0500);
joystick_tests(0x0300);
CoUninitialize(); CoUninitialize();
} }