Some experimenting with modifying the Joystick::Initialize function and I found some weird output. The modified method is at the end of the post. This is the output it gives me:
Entered Joystick::Initialize(0)
ERROR: JOYERR_PARMS on index '0'.
Entered Joystick::Initialize(1)
For Joystick::Initialize(0)
Not the requested index: '0'. '1' requested.
ERROR: JOYERR_PARMS on index '1'.
So basically, when the method is run with 0 as parameter, joyGetPosEx instantly returns JOYERR_PARMS. When Initialize is run with 1 as index however, it finds one joystick with index 0, but since the requested index was 1 it chooses to ignore this. Quite odd. :?
void Joystick::Initialize(unsigned int Index)
{
// Reset state
myIndex = JOYSTICKID1;
myNbAxes = 0;
myNbButtons = 0;
std::cout << "Entered Joystick::Initialize(" << Index << ")" << std::endl;
// Get the Index-th connected joystick
MMRESULT Error;
JOYINFOEX JoyInfo;
unsigned int NbFound = 0;
for (NbFound = 0; (Error = joyGetPosEx(myIndex, &JoyInfo)) != JOYERR_PARMS; myIndex++)
{
std::cout << "For Joystick::Initialize(" << NbFound << ")" << std::endl;
// Check if the current joystick is connected
if (Error == JOYERR_NOERROR)
{
// Check if it's the required index
if (NbFound == Index)
{
// Ok : store its parameters and return
JOYCAPS Caps;
joyGetDevCaps(myIndex, &Caps, sizeof(Caps));
myNbAxes = Caps.wNumAxes;
myNbButtons = Caps.wNumButtons;
if (myNbButtons > JoystickState::MaxButtons)
myNbButtons = JoystickState::MaxButtons;
return;
}
else
{
std::cout << "Not the requested index: '" << NbFound << "'. '" << Index << "' requested." << std::endl;
}
// Go to the next valid joystick
++NbFound;
}
}
std::cout << "ERROR: " << (Error == JOYERR_PARMS ? "JOYERR_PARMS" : "NONE") << " on index '" << NbFound << "'. " << std::endl << std::endl;
}