Skip to content
Nemirtingas edited this page May 26, 2024 · 1 revision

Compiling

Checkout the Xinput1_3 or Xinput1_4 branch depending on the Windows version you want to support. This project is built using CMake.

What changed?

Some functions have a documentation where Xinput didn't, like:

  • XInputGetStateEx
  • XInputWaitForGuideButton
  • XInputCancelGuideButtonWait
  • XInputPowerOffController
  • XInputGetBaseBusInformation
  • XInputGetCapabilitiesEx

As well as some functions to extends the range of Xinput:

  • OpenXInputGetMaxControllerCount
  • OpenXInputGetDeviceUSBIds
  • OpenXInputGetStateFull

How to use?

The usage of this library is the same as Xinput.

To keep you application compatible with Xinput, I strongly advise you to keep your base code like before but changing your use of XUSER_MAX_COUNT for a variable storing the max gamepad count, like :

static DWORD XinputMaxControllerCount = XUSER_MAX_COUNT;

Then checking if the Xinput library you are using is OpenXinput or Xinput by doing so:

HMODULE hXinput = GetModuleHandleW(L"Xinput1_4.dll");
if (hXinput != NULL)
{
    OpenXInputGetMaxControllerCount_t* pfnOpenXInputGetMaxControllerCount_t = (OpenXInputGetMaxControllerCount_t*)GetProcAddress(hXinput, "OpenXInputGetMaxControllerCount");
    if (pfnOpenXInputGetMaxControllerCount_t != nullptr)
    {// We are using OpenXinput, check for the max controller count.
        XinputMaxControllerCount = pfnOpenXInputGetMaxControllerCount_t();
    }

    pOpenXInputGetDeviceUSBIds = (OpenXInputGetDeviceUSBIds_t*)GetProcAddress(hXinput, "OpenXInputGetDeviceUSBIds");
    pOpenXInputGetStateFull = (OpenXInputGetStateFull_t*)GetProcAddress(hXinput, "OpenXInputGetStateFull");
}

And now, instead of the common example of:

for (int i = 0; i < XUSER_MAX_COUNT; ++i)
{
    XInput*(i, ...);
    ...
}

You can just use your variable:

for (int i = 0; i < XinputMaxControllerCount; ++i)
{
    XInput*(i, ...);
    ...
}

Clone this wiki locally