I have written the following but when I have dwUserIndex as 0,1,2,3
or
any number, doesn't really matter, it always returns ERROR_BAD_ARGUMENTS.
Not sure why it's not returning ERROR_DEVICE_NOT_CONNECTED for you. I'll just point out:
Probably the calling convention is wrong. Usually Windows API functions have to be declared like this:
DWORD WINAPI XInputGetState(DWORD dwUserIndex, XINPUT_STATE* pState);
The difference is (among others) that the first parameter is passed in the ECX register instead of the stack