Question

I want to write a program interacting with joystick. I am using a standard SDK example and dinput8.lib.

Here's the code. GUID Is taken from enumJoysticksCallback function. I throw away everything to minimise chance of error.

LPDIRECTINPUT8          g_pDI = NULL;
LPDIRECTINPUTDEVICE8    g_pJoystick = NULL;

HRESULT hr = DirectInput8Create ( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&g_pDI, NULL );

    GUID  *GUID_Saitek = new _GUID ;
    GUID_Saitek->Data1 = 0xA00DBD70;
    GUID_Saitek->Data2 = 0x7FB5;
    GUID_Saitek->Data3 = 0x11E3;
    char tmp[8] = { 0x80, 0x3, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0 };
    memcpy(GUID_Saitek->Data4, tmp, 8);

    g_pDI->CreateDevice( *GUID_Saitek, &g_pJoystick, NULL );
    hr = g_pJoystick->SetDataFormat( &c_dfDIJoystick2 ) ;

Program fails on this string

hr = g_pJoystick->SetDataFormat( &c_dfDIJoystick2 );

hr returns 0x80070216 which seems to be ERROR_ARITHMETIC_OVERFLOW.

&c_dfDIJoystick instead of &c_dfDIJoystick2 does not help too.

For mouse it is the same...

LPDIRECTINPUT8          di = NULL;
LPDIRECTINPUTDEVICE8    Mouse = NULL;
HRESULT hr = DirectInput8Create(GetModuleHandle( NULL ),  DIRECTINPUT_VERSION, IID_IDirectInput8,  (VOID**)&di, NULL);
hr = di->CreateDevice( GUID_SysMouse, &Mouse, NULL );
hr = Mouse->SetDataFormat( &c_dfDIMouse ) ;

hr returns 0x80070216 again The example application "Joystick.exe" works no problem.

GetCapabilities returns some random stuff which is definately not true

  • Embarcadero RAD Studio XE5/Borland CPP Builder 6 (both have same results)
  • DirectInput Saitek Rudder Pedals/Saitek X52 controllers (both crash program)
  • 32bit app
  • standard SDK example "Joystick"

What is wrong? Error does not match anything related to directinput. Device creates with no errors but any work with it leads to errors.

Thanks!

UPDATE: SetCooperativeLevel function returns 0x80070006 which is ERROR_INVALID_HANDLE

Was it helpful?

Solution

Finally I found out what was the problem. It lied here: &c_dfDIJoystick2

For some reason Microsoft attached pre-defined structures that do not match anythig. Even &c_dfDIMouse does not match my simple 3 button mouse. The answer came with another sample code "Custom Format". You have to make a new format structure for each device because even EnumObjects function will not make it for you, which makes DirectInput quite inconvenient.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top