Since windows and linux source differ on this case, I made a patch to make windows code similar to linux:
Index: branches/sfml2/src/SFML/Window/Win32/Joystick.cpp
===================================================================
--- branches/sfml2/src/SFML/Window/Win32/Joystick.cpp (revision 1194)
+++ branches/sfml2/src/SFML/Window/Win32/Joystick.cpp (working copy)
@@ -42,6 +42,7 @@
void Joystick::Initialize(unsigned int index)
{
// Reset state
+ myPresent = false;
myIndex = JOYSTICKID1;
myNbAxes = 0;
myNbButtons = 0;
@@ -62,6 +63,7 @@
// Ok : store its parameters and return
JOYCAPS caps;
joyGetDevCaps(myIndex, &caps, sizeof(caps));
+ myPresent = true;
myNbAxes = caps.wNumAxes;
myNbButtons = caps.wNumButtons;
if (myNbButtons > JoystickState::MaxButtons)
@@ -84,6 +86,10 @@
{
JoystickState state = {0};
+ // Check if joystick is present
+ if (!myPresent)
+ return state;
+
// Get the joystick caps (for range conversions)
JOYCAPS caps;
if (joyGetDevCaps(myIndex, &caps, sizeof(caps)) == JOYERR_NOERROR)
Index: branches/sfml2/src/SFML/Window/Win32/Joystick.hpp
===================================================================
--- branches/sfml2/src/SFML/Window/Win32/Joystick.hpp (revision 1194)
+++ branches/sfml2/src/SFML/Window/Win32/Joystick.hpp (working copy)
@@ -78,6 +78,7 @@
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
+ bool myPresent; ///< Is joystick present
unsigned int myIndex; ///< Windows ID of the joystick
unsigned int myNbAxes; ///< Number of axis supported by the joystick
unsigned int myNbButtons; ///< Number of buttons supported by the joystick
Edit: typo