Kaije
Kaije

Reputation: 2661

converting array of bytes to UTF-8 unicode

I have a file saved as UTF-8, and i'm reading it like this:

ReadFile(hFile, pContents, pFile->nFileSize, &dwRead, NULL);

(pContents is a BYTE* of size nFileSize)

its just a small file with 100 bytes or so, contains text which i want to read into memory in wchar_t* format, so i can set the text of edit and static controls with the unicode text.

How can i convert the bytes to UTF-8?

edit (i don't want to use fstream or wfstream)

Upvotes: 0

Views: 8932

Answers (3)

user565447
user565447

Reputation: 999

int res2 = WideCharToMultiByte(CP_UTF8, 0, tempBuf.c_str(), -1, 
                               multiByteBuf, lengthOfInputString, NULL, NULL);
int res = MultiByteToWideChar(CP_UTF8, 0, buf, -1, wcharBuf, lengthOfInputString);

Upvotes: 1

Loki Astari
Loki Astari

Reputation: 264381

If the file is in UTF-8 and you read it into an array.
Then it is still in UTF-8 format and you don;t need to do anything.

Upvotes: 4

dan04
dan04

Reputation: 90995

Upvotes: 6

Related Questions