CInternetSession read unicode

Flaviu_ 791 Reputation points

The project is MFC/Unicode (Use Unicode Character Set). Here is a little code that get strings from an address:

	CString sOutput;
	CInternetSession session{};

	char buffer[256]; 
	CStdioFile file = session.OpenURL(address, 1, INTERNET_FLAG_TRANSFER_ASCII);
	while (UINT nRead = file->Read(buffer, sizeof(buffer - 1)))
		buffer[nRead] = '\0';
		sOutput += buffer;

The problem is that I got non-unicode string, even if CString is UNICODE (CStringW). Example:


which is non UNICODE. If I change char to wchar_t, I got even worst:


How can adapt the code to read UNICODE?

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,323 questions
{count} vote

Accepted answer
  1. RLWA32 37,121 Reputation points

    You mean byte by byte, at this point?
    sOutput += buffer;

    I mean that you convert the entire buffer to utf-16le BEFORE that statement. Once you have obtained a utf-16le encoded string you should be able to work with that and CString without problems.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful