Mick Mick - 1 year ago 182
C Question

WinHttpSendRequest returns ERROR_INVALID_PARAMETER

I am attempting to get the betfair API working with windows API.

I am stuck attempting to login with the following code (username and passwords have been changed).

char *headers = "X-Application: MakJhSABCDq8sbPIr\r\nAccept: application/json";

char *usernameandpassword = "username=mick&password=xyz123";


but the call is returning with the value ERROR_INVALID_PARAMETER. But I have no idea which parameter is bad.

Answer Source

LPCWSTR as a type-definition for const wchar_t*. on windows, that UTF16 encoding. basically, you brutally casted an ASCII string(headers) to a wide character string and told Windows to calculate its length, which fails since it's not a valid wide string.

a solution to that is to use wide string for the first place:

const wchar_t *headers = L"X-Application: MakJhSABCDq8sbPIr\r\nAccept: application/json";

anyway, pointing to a string literal with a char* is wrong, since string literals are not modifiable, modifying them is undefined behavior. it should always be const