XInputGetState returns 1167

XInputGetState is returning ERROR_DEVICE_NOT_CONNECTED (1167) despite the following:

My Logitech F310 controller is plugged in
The controller is set to XInput Mode
The XInput 1.4 DLL is confirmed loaded
I have a valid function pointer to the XInputGetState function in the DLL (it's not the stub)

Yet when the function call is made I get a return value of 1167 back! The controller shows up in Windows and even works to launch things like Steam's Big Picture mode. This used to work!

I'm on Day 23 of Handmade Hero. I've downloaded the source code and Casey's works but I have no idea why. I have diff'd the source code with mine to no end but I don't see what I'm doing wrong as far as the controller related code is concerned.

Does anyone have any ideas on what could be going on here? I'm at a loss. There has to be a bug somewhere.

Here are my project files in case a kind soul wants to review.

My Project Files

Edited by mdeforge on
Are you sure ERROR_DEVICE_NOT_CONNECTED is returned for all ControllerIndex values (0 to 3)?

I tried your code and it works for me with Xbox One controller - XInputGetState returned ERROR_SUCCESS for ControllerIndex=0.

Edited by Mārtiņš Možeiko on
Thanks for the sanity check! You were right, I wasn't looking at the other index's. I actually just added that back in since I didn't want to support 4 controllers, but then I realized it's important because the controller could be any one of those ID's.

The problem of why I wasn't getting any input came down to this line in handmade.cpp:
1
game_controller_input *Controller = GetController(Input, 0);


I think this works for some, and for Casey on the stream, because their controller is ID 0. Mine is ID 1 for some reason (hence why I didn't catch the index above too). Once I chanced it to the following I started seeing input again!

1
game_controller_input *Controller = GetController(Input, ControllerIndex);


Thanks!
That's because "Input" array includes keyboard as controller with index 0. Because keyboard is always present, so code puts it in index 0. All other optional controllers get assigned indices [1..4]. So if XInput controller index is 0, that maps to your index 1. If XInput controller index is 3, that maps to your index 4.