We've an old C++ app that's making calls to third-party webservices, using WinHttp.WinHttpRequest.5.1.
I won't list all of the details of the call sequence, as I don't think it's relevant to the problem, but we finish by calling hr = pIWinHttpRequest->get_ResponseText(&bstrResponse);
, where bstrResponse
is of type BSTR.
The calling code doesn't work with BSTRs, it works with standard C/C++ char *
's, so the code converts the BSTR to a char *
with:
_bstr_t b(bstrResponse);
const char *c = static_cast<char *>(b);
And for all of the prior webservices we've accessed with this code, this has worked. But for this new one, it's not.
The data we're getting back is supposed to be XML, but for this one webservice, it looks like we're getting some character code conversion problems. Our resulting string starts with; "?<?xml version="1.0" encoding="utf-8"?>..."
Notice the extra ?
at the beginning. When walking through this in the debugger, we don't see this in displayed value of bstrResponse
, and we don't see it in the displayed value of b
, but we do see it in the displayed value of c
.
Any ideas as to what might be going on?
EDITED
I understand that BSTR is a multi-byte type, but all of the characters in this string are plain ASCII, and none of the code that calls this function can handle multi-byte characters. Browsing around the web, I see this specific mechanism recommended frequently, but in this case, it doesn't work.
I need to convert this string from BSTR to an array of single-byte characters. Even if that means stripping out multi-byte characters that cannot be converted.