The Windows 8 Consumer Preview includes version 1.4 of the XInput API for use with Xbox 360 Common Controller compatible game devices, and this API is fully supported for both Windows Store apps (including x86, x64, and Windows on ARM) and desktop Win32 applications. The full details of the differences compared to XInput 1.3 which shipped in the DirectX SDK (June 2010) release are addressed on MSDN. The headers and libraries for Xinput 1.4 are included in the Windows SDK 8.0 that is part Visual Studio 11 Beta. Windows 8 also includes an updated driver for these devices, XUSB22.SYS.

Update: This information also applies to Windows 8 Release Preview / RTM and Visual Studio 2012 RC / RTM. XINPUT 1.4 is supported on Windows RT as well.

REDIST: For XInput 1.4 on Windows 8 and Windows RT, no redistribution is required since XInput 1.4 is included with the OS. For XInput 9.1.0 on Windows Vista, Windows 7, or WIndows 8, no redistribution is required since XInput 9.1.0 is included with the OS. For XInput 1.3 on any version of Windows, use the legacy DirectX SDK REDIST.

Since Xinput version 1.4 is not available on Windows 7, Win32 desktop games that support older versions of Windows can use either XInput 1.3 or the still supported older XInput 9.1.0 which is included in Windows Vista, Windows 7, and Windows 8.

  • When building an application that is 'down-level' using headers in the Windows 8.0 SDK, be sure to explicitly select the correct 'minimum' _WIN32_WINNT value. For Windows 8, that is 0x0602 (which is the default when building code with Visual Studio 2012 and for all Windows Store apps). For Windows 7 use 0x0601, and for Windows Vista use 0x0600. Typically this is done as part of the project configuration via Preprocessor Definitions.

If you set _WIN32_WINNT correctly and try building with the Windows 8.0 SDK version of the xinput.h header, you will be using XInput 1.4 if set to 0x0602, or XInput 9.1.0 otherwise. If using XInput 1.4, you should link with XINPUT.LIB. If using XInput 9.1.0, link with XINPUT9_1_0.LIB instead.

If your usage of XInput is limited to basic gamepad functionality via XInputGetState and XInputSetState, then XInput 9.1.0 may be all the functionailty you require and is supported on a broad range of Windows OSes without the need to use the DirectSetup redistribution package. A few things to note about XInput 9.1.0 are that XInputGetCapabilities returns a fixed set of values regardless of the attached device (notably including the subtype), and this version of XInput does not support headset audio functionality.

The following code will compile using all three versions of XInput:

 #include <xinput.h>

XINPUT_STATE state;
memset( &state, 0, sizeof(XINPUT_STATE) );

if( XInputGetState( 0, &state ) == ERROR_SUCCESS )
{
// Controller is connected
if ( state.Gamepad.wButtons & XINPUT_GAMEPAD_A )
{
// Button A is pressed
}

XINPUT_VIBRATION motor;
memset( &motor, 0, sizeof(XINPUT_VIBRATION) );

if ( state.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD )
{
motor.wLeftMotorSpeed = state.Gamepad.bLeftTrigger << 8;
}

if ( state.Gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD )
{
motor.wRightMotorSpeed = state.Gamepad.bRightTrigger << 8;
}

XInputSetState( 0, &motor );

}
else
{
// Controller is not connected, shouldn't recheck it for a few seconds
}

If using the XInput 1.3 solution, You should follow the instructions on MSDN to use the Windows 8.0 SDK headers and libraries where possible and explicitly link to the DXSDK_DIR for the headers where you need older versions to support older versions of Windows. (see "Where is the DirectX SDK?").

In a future post, I'll address the details of using XInput 1.4's audio features, and how to implement similiar behavior down-level using XInput 1.3. XInput 9.1.0 doesn't support audio features.

Note: The Windows 7.1 SDK includes the xinput.h header and xinput.lib import library for the the Xinput 9.1.0 version as well. XInput 9.1.0 can be deployed on Windows XP using the legacy DirectX SDK's REDIST (aka DirectSetup).

Windows Server: Note that XInput is not included in Windows Server 2012. XInput 9.1.0 is also not present on Windows Server 2008 or 2012.

Xbox One Controller: The Xbox One controller is not supported by the XUSB21.SYS (Windows 7) or XUSB22.SYS (Windows 8.x) driver. There is a X1USB1.SYS driver now available which does support the Xbox One Controller for XINPUT when using a micro-USB cable--the Xbox One controller is not compatible with the Xbox 360 Wireless Receiver for Windows.

Related: XInput Win32 Samples, Game controller sample