C++ get the length of LPCWSTR and LPVOID

Forivin picture Forivin · Apr 13, 2014 · Viewed 15k times · Source

The winapi function WinHttpSendRequest() wants the size of the second parameter in the third one and the size of the fourth parameter in the fifth one.
How can I calculate it?
I have a function wrapped around it and I pass the strings directly, about like this:

void Req(LPCWSTR headers, LPVOID body) {
    WinHttpSendRequest( hRequest, headers, (DWORD)strlen(headers), body, (DWORD)strlen(body), 0, 0 );
}
Req(L"User-Agent: blabla/1.0\r\nConnection: Keep Alive", "asdf=qwer&abcd=1234);

The above code doesn't work. :/
I hope you can help me out.

Answer

ooga picture ooga · Apr 13, 2014

.You need to use wcslen instead of strlen for wide-strings.