src/joystick/windows/SDL_dxjoystick.c
changeset 7037 3fedf1f25b94
parent 6993 33f1e384ed56
child 7133 87d4cb9bb66c
     1.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Fri Mar 29 21:29:57 2013 -0400
     1.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Sun Mar 31 12:48:50 2013 -0400
     1.3 @@ -159,7 +159,7 @@
     1.4  static JoyStick_DeviceData *SYS_Joystick;    /* array to hold joystick ID values */
     1.5  
     1.6  /* local prototypes */
     1.7 -static void SetDIerror(const char *function, HRESULT code);
     1.8 +static int SetDIerror(const char *function, HRESULT code);
     1.9  static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE *
    1.10                                             pdidInstance, VOID * pContext);
    1.11  static BOOL CALLBACK EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev,
    1.12 @@ -352,14 +352,14 @@
    1.13  
    1.14  
    1.15  /* Convert a DirectInput return code to a text message */
    1.16 -static void
    1.17 +static int
    1.18  SetDIerror(const char *function, HRESULT code)
    1.19  {
    1.20      /*
    1.21 -    SDL_SetError("%s() [%s]: %s", function,
    1.22 +    return SDL_SetError("%s() [%s]: %s", function,
    1.23                   DXGetErrorString9A(code), DXGetErrorDescription9A(code));
    1.24       */
    1.25 -    SDL_SetError("%s() DirectX error %d", function, code);
    1.26 +    return SDL_SetError("%s() DirectX error %d", function, code);
    1.27  }
    1.28  
    1.29  
    1.30 @@ -565,17 +565,13 @@
    1.31  
    1.32  	if (!RegisterClassEx (&wincl))
    1.33  	{		
    1.34 -		SDL_SetError("Failed to create register class for joystick autodetect.",
    1.35 -		GetLastError());
    1.36 -		return -1;
    1.37 +		return SDL_SetError("Failed to create register class for joystick autodetect.", GetLastError());
    1.38  	}
    1.39  
    1.40  	messageWindow = (HWND)CreateWindowEx( 0,  L"Message", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL );
    1.41  	if ( !messageWindow )
    1.42  	{
    1.43 -		SDL_SetError("Failed to create message window for joystick autodetect.",
    1.44 -			GetLastError());
    1.45 -		return -1;
    1.46 +		return SDL_SetError("Failed to create message window for joystick autodetect.", GetLastError());
    1.47  	}
    1.48  
    1.49  	SDL_memset(&dbh, 0x0, sizeof(dbh));
    1.50 @@ -587,9 +583,7 @@
    1.51  	hNotify = RegisterDeviceNotification( messageWindow, &dbh, DEVICE_NOTIFY_WINDOW_HANDLE );
    1.52  	if ( !hNotify )
    1.53  	{
    1.54 -		SDL_SetError("Failed to create notify device for joystick autodetect.",
    1.55 -			GetLastError());
    1.56 -		return -1;
    1.57 +		return SDL_SetError("Failed to create notify device for joystick autodetect.", GetLastError());
    1.58  	}
    1.59  
    1.60  	SDL_LockMutex( s_mutexJoyStickEnum );
    1.61 @@ -674,8 +668,7 @@
    1.62  
    1.63      result = WIN_CoInitialize();
    1.64      if (FAILED(result)) {
    1.65 -        SetDIerror("CoInitialize", result);
    1.66 -        return (-1);
    1.67 +        return SetDIerror("CoInitialize", result);
    1.68      }
    1.69  
    1.70      coinitialized = SDL_TRUE;
    1.71 @@ -685,24 +678,20 @@
    1.72  
    1.73      if (FAILED(result)) {
    1.74          SDL_SYS_JoystickQuit();
    1.75 -        SetDIerror("CoCreateInstance", result);
    1.76 -        return (-1);
    1.77 +        return SetDIerror("CoCreateInstance", result);
    1.78      }
    1.79  
    1.80      /* Because we used CoCreateInstance, we need to Initialize it, first. */
    1.81      instance = GetModuleHandle(NULL);
    1.82      if (instance == NULL) {
    1.83          SDL_SYS_JoystickQuit();
    1.84 -        SDL_SetError("GetModuleHandle() failed with error code %d.",
    1.85 -                     GetLastError());
    1.86 -        return (-1);
    1.87 +        return SDL_SetError("GetModuleHandle() failed with error code %d.", GetLastError());
    1.88      }
    1.89      result = IDirectInput8_Initialize(dinput, instance, DIRECTINPUT_VERSION);
    1.90  
    1.91      if (FAILED(result)) {
    1.92          SDL_SYS_JoystickQuit();
    1.93 -        SetDIerror("IDirectInput::Initialize", result);
    1.94 -        return (-1);
    1.95 +        return SetDIerror("IDirectInput::Initialize", result);
    1.96      }
    1.97  
    1.98      s_mutexJoyStickEnum = SDL_CreateMutex();
    1.99 @@ -967,8 +956,7 @@
   1.100      joystick->hwdata =
   1.101          (struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
   1.102      if (joystick->hwdata == NULL) {
   1.103 -        SDL_OutOfMemory();
   1.104 -        return (-1);
   1.105 +        return SDL_OutOfMemory();
   1.106      }
   1.107      SDL_memset(joystick->hwdata, 0, sizeof(struct joystick_hwdata));
   1.108      joystick->hwdata->buffered = 1;
   1.109 @@ -1040,8 +1028,7 @@
   1.110  			IDirectInput8_CreateDevice(dinput,
   1.111  									  &(joystickdevice->dxdevice.guidInstance), &device, NULL);
   1.112  		if (FAILED(result)) {
   1.113 -			SetDIerror("IDirectInput::CreateDevice", result);
   1.114 -			return (-1);
   1.115 +			return SetDIerror("IDirectInput::CreateDevice", result);
   1.116  		}
   1.117  
   1.118  		/* Now get the IDirectInputDevice8 interface, instead. */
   1.119 @@ -1053,8 +1040,7 @@
   1.120  		IDirectInputDevice8_Release(device);
   1.121  
   1.122  		if (FAILED(result)) {
   1.123 -			SetDIerror("IDirectInputDevice8::QueryInterface", result);
   1.124 -			return (-1);
   1.125 +			return SetDIerror("IDirectInputDevice8::QueryInterface", result);
   1.126  		}
   1.127  
   1.128  		/* Aquire shared access. Exclusive access is required for forces,
   1.129 @@ -1065,8 +1051,7 @@
   1.130  													DISCL_NONEXCLUSIVE |
   1.131  													DISCL_BACKGROUND);
   1.132  		if (FAILED(result)) {
   1.133 -			SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result);
   1.134 -			return (-1);
   1.135 +			return SetDIerror("IDirectInputDevice8::SetCooperativeLevel", result);
   1.136  		}
   1.137  
   1.138  		/* Use the extended data structure: DIJOYSTATE2. */
   1.139 @@ -1074,8 +1059,7 @@
   1.140  			IDirectInputDevice8_SetDataFormat(joystick->hwdata->InputDevice,
   1.141  											  &c_dfDIJoystick2);
   1.142  		if (FAILED(result)) {
   1.143 -			SetDIerror("IDirectInputDevice8::SetDataFormat", result);
   1.144 -			return (-1);
   1.145 +			return SetDIerror("IDirectInputDevice8::SetDataFormat", result);
   1.146  		}
   1.147  
   1.148  		/* Get device capabilities */
   1.149 @@ -1084,8 +1068,7 @@
   1.150  												&joystick->hwdata->Capabilities);
   1.151  
   1.152  		if (FAILED(result)) {
   1.153 -			SetDIerror("IDirectInputDevice8::GetCapabilities", result);
   1.154 -			return (-1);
   1.155 +			return SetDIerror("IDirectInputDevice8::GetCapabilities", result);
   1.156  		}
   1.157  
   1.158  		/* Force capable? */
   1.159 @@ -1094,8 +1077,7 @@
   1.160  			result = IDirectInputDevice8_Acquire(joystick->hwdata->InputDevice);
   1.161  
   1.162  			if (FAILED(result)) {
   1.163 -				SetDIerror("IDirectInputDevice8::Acquire", result);
   1.164 -				return (-1);
   1.165 +				return SetDIerror("IDirectInputDevice8::Acquire", result);
   1.166  			}
   1.167  
   1.168  			/* reset all accuators. */
   1.169 @@ -1106,17 +1088,14 @@
   1.170  
   1.171  			/* Not necessarily supported, ignore if not supported.
   1.172  			if (FAILED(result)) {
   1.173 -				SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand",
   1.174 -						   result);
   1.175 -				return (-1);
   1.176 +				return SetDIerror("IDirectInputDevice8::SendForceFeedbackCommand", result);
   1.177  			}
   1.178  			*/
   1.179  
   1.180  			result = IDirectInputDevice8_Unacquire(joystick->hwdata->InputDevice);
   1.181  
   1.182  			if (FAILED(result)) {
   1.183 -				SetDIerror("IDirectInputDevice8::Unacquire", result);
   1.184 -				return (-1);
   1.185 +				return SetDIerror("IDirectInputDevice8::Unacquire", result);
   1.186  			}
   1.187  
   1.188  			/* Turn on auto-centering for a ForceFeedback device (until told
   1.189 @@ -1131,8 +1110,7 @@
   1.190  
   1.191  			/* Not necessarily supported, ignore if not supported.
   1.192  			if (FAILED(result)) {
   1.193 -				SetDIerror("IDirectInputDevice8::SetProperty", result);
   1.194 -				return (-1);
   1.195 +				return SetDIerror("IDirectInputDevice8::SetProperty", result);
   1.196  			}
   1.197  			*/
   1.198  		}
   1.199 @@ -1160,8 +1138,7 @@
   1.200  			 * to use less reliable polling. */
   1.201  			joystick->hwdata->buffered = 0;
   1.202  		} else if (FAILED(result)) {
   1.203 -			SetDIerror("IDirectInputDevice8::SetProperty", result);
   1.204 -			return (-1);
   1.205 +			return SetDIerror("IDirectInputDevice8::SetProperty", result);
   1.206  		}
   1.207  	}
   1.208      return (0);