src/joystick/windows/SDL_dxjoystick.c
changeset 6965 ab4bb4e99961
parent 6885 700f1b25f77f
child 6971 5ded971ee761
     1.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Tue Mar 05 17:59:36 2013 -0500
     1.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Tue Mar 05 18:01:59 2013 -0500
     1.3 @@ -73,6 +73,7 @@
     1.4  static SDL_Thread *s_threadJoystick = NULL;
     1.5  static SDL_bool s_bJoystickThreadQuit = SDL_FALSE;
     1.6  static HANDLE s_pXInputDLL = 0;
     1.7 +static SDL_bool s_bXInputEnabled = SDL_TRUE;
     1.8  
     1.9  extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
    1.10                                         LPDIRECTINPUT * ppDI,
    1.11 @@ -364,6 +365,11 @@
    1.12  	HRESULT                 hr;
    1.13  	DWORD bCleanupCOM;
    1.14  
    1.15 +    if (!s_bXInputEnabled)
    1.16 +    {
    1.17 +        return SDL_FALSE;
    1.18 +    }
    1.19 +
    1.20  	SDL_memset( pDevices, 0x0, sizeof(pDevices) );
    1.21  
    1.22  	// CoInit if needed
    1.23 @@ -569,7 +575,7 @@
    1.24  			}
    1.25  		}
    1.26  
    1.27 -		if ( XINPUTGETCAPABILITIES )
    1.28 +		if ( s_bXInputEnabled && XINPUTGETCAPABILITIES )
    1.29  		{
    1.30  			// scan for any change in XInput devices
    1.31  			for ( userId = 0; userId < 4; userId++ )
    1.32 @@ -627,6 +633,10 @@
    1.33  {
    1.34      HRESULT result;
    1.35      HINSTANCE instance;
    1.36 +	const char *env = SDL_GetHint(SD_HINT_XINPUT_ENABLED);
    1.37 +	if (env && !SDL_atoi(env)) {
    1.38 +		s_bXInputEnabled = SDL_FALSE;
    1.39 +	}
    1.40  
    1.41      result = WIN_CoInitialize();
    1.42      if (FAILED(result)) {
    1.43 @@ -666,23 +676,25 @@
    1.44  	s_bDeviceAdded = SDL_TRUE; // force a scan of the system for joysticks this first time
    1.45  	SDL_SYS_JoystickDetect();
    1.46  
    1.47 -	// try to load XInput support if available
    1.48 -	s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" );
    1.49 -	if ( !s_pXInputDLL )
    1.50 -		s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" );
    1.51 -	if ( s_pXInputDLL )
    1.52 -	{
    1.53 -		// 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think...
    1.54 -		PC_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 );
    1.55 -		PC_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" );
    1.56 -		PC_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" );
    1.57 -		if ( !PC_XInputGetState || !PC_XInputSetState || !PC_XInputGetCapabilities )
    1.58 +    if (s_bXInputEnabled) {
    1.59 +		// try to load XInput support if available
    1.60 +		s_pXInputDLL = LoadLibrary( L"XInput1_3.dll" );
    1.61 +		if ( !s_pXInputDLL )
    1.62 +			s_pXInputDLL = LoadLibrary( L"bin\\XInput1_3.dll" );
    1.63 +		if ( s_pXInputDLL )
    1.64  		{
    1.65 -			SDL_SYS_JoystickQuit();
    1.66 -			SDL_SetError("GetProcAddress() failed when loading XInput.", GetLastError());
    1.67 -			return (-1);
    1.68 +			// 100 is the ordinal for _XInputGetStateEx, which returns the same struct as XinputGetState, but with extra data in wButtons for the guide button, we think...
    1.69 +			PC_XInputGetState = (XInputGetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, (LPCSTR)100 );
    1.70 +			PC_XInputSetState = (XInputSetState_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputSetState" );
    1.71 +			PC_XInputGetCapabilities = (XInputGetCapabilities_t)GetProcAddress( (HMODULE)s_pXInputDLL, "XInputGetCapabilities" );
    1.72 +			if ( !PC_XInputGetState || !PC_XInputSetState || !PC_XInputGetCapabilities )
    1.73 +			{
    1.74 +				SDL_SYS_JoystickQuit();
    1.75 +				SDL_SetError("GetProcAddress() failed when loading XInput.", GetLastError());
    1.76 +				return (-1);
    1.77 +			}
    1.78  		}
    1.79 -	}
    1.80 +    }
    1.81  
    1.82  
    1.83  	if ( !s_threadJoystick )
    1.84 @@ -934,6 +946,7 @@
    1.85  
    1.86      /* allocate memory for system specific hardware data */
    1.87  	joystick->instance_id = joystickdevice->nInstanceID;
    1.88 +    joystick->closed = 0;
    1.89      joystick->hwdata =
    1.90          (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
    1.91      if (joystick->hwdata == NULL) {
    1.92 @@ -959,7 +972,7 @@
    1.93  				userId++;
    1.94  		}
    1.95  
    1.96 -		if ( XINPUTGETCAPABILITIES )
    1.97 +		if ( s_bXInputEnabled && XINPUTGETCAPABILITIES )
    1.98  		{
    1.99  			result = XINPUTGETCAPABILITIES( userId, XINPUT_FLAG_GAMEPAD, &capabilities );
   1.100  			if ( result == ERROR_SUCCESS )