Called ReadFile in a text file, got weird (Japanese?) Characters

I use the following code to read all the elements from a file with a descriptor hFilethat works and with its size that I got from GetFileSize(hFile, NULL).

_TCHAR* text = (_TCHAR*)malloc(sizeOfFile * sizeof(_TCHAR));
DWORD numRead = 0;
BOOL didntFail = ReadFile(hFile, text, sizeOfFile, &numRead, NULL);

after the operation, textthere is some strange thing in Japanese or something like that, and not the contents of the file.

What did I do wrong?

edit: I understand that this is a coding problem, but then how will I convert the text to LPCWSTR to use things like WriteConsoleOutputCharacter

+3
source share
3 answers

IDE Unicode, _TCHAR wchar_t. ReadFile() , _TCHAR, 8- , Unicode UTF-16. CJK (//).

:

Unicode -Unicode, , ( ).

, Windows Unicode, ANSI- Windows (, WriteConsoleOutputCharacterA).

+6

. , 8- , , , TCHAR UNICODE, 16- . Fix:

 char* text = (char*)malloc(...);

, . , utf-8. 8- TCHAR (wchar_t, ) MultiByteToWideChar(). , .

+2

ANSI UTF-8 UTF-16.

+1

All Articles