I've started to follow the Handmade Hero series. He's loading XInput manually, and has therefore created a function stub. It looks like this:
#define X_INPUT_GET_STATE(name) DWORD WINAPI name(DWORD dwUserIndex, XINPUT_STATE *pState)
typedef X_INPUT_GET_STATE(x_input_get_state);
X_INPUT_GET_STATE(XInputGetStateStub) {
return 0;
}
global_variable x_input_get_state *XInputGetState_ = XInputGetStateStub;
#define XInputGetState XInputGetState_;
This is defined above any other functions. global_variable is a #define of static.
This code very nearly works. It compiles successfully if I use if (XInputGetState_(ControllerIndex, &ControllerState) == ERROR_SUCCESS)
but doesn't compile when I use if (XInputGetState(ControllerIndex, &ControllerState) == ERROR_SUCCESS)
However, I can do as follows.
auto func = XInputGetState(ControllerIndex, &ControllerState);
if (func(ControllerIndex, &ControllerState) == ERROR_SUCCESS)
I'm utterly lost as to why this is happening.
You can find the official function definition here
EDIT:
Just to make matters more confusing. The XInputSetState function is also being defined manually.
#define X_INPUT_SET_STATE(name) DWORD WINAPI name(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration)
typedef X_INPUT_SET_STATE(x_input_set_state);
X_INPUT_SET_STATE(XInputSetStateStub) {
return 0;
}
global_variable x_input_set_state *XInputSetState_ = XInputSetStateStub;
#define XInputSetState XInputSetState_;
I can then call the function like this
XINPUT_VIBRATION Vibration;
Vibration.wLeftMotorSpeed = 60000;
Vibration.wRightMotorSpeed = 60000;
XInputSetState(0, Vibration);
This code runs and compiles without any problems;
Thanks for the help!