How to use ReadFile to read a buffer as wchar_t array and then output it to the console
DWORD read_output()
{
BOOL success = FALSE;
DWORD dwRead;
HANDLE handle = CreateFileW(L"data.txt",
GENERIC_READ,
0,
NULL,
3,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (handle == INVALID_HANDLE_VALUE)
printf("Failed to open file\n");
do
{
wchar_t buffer[128];
success = ReadFile(handle, buffer, 128, &dwRead, NULL);
wprintf(L"%s", buffer);
} while(!success || dwRead == 0);
return 0;
}
int main()
{
_setmode(fileno(stdout), _O_U16TEXT);
read_output();
}
This is the kind of output I get
ШиÑ
Ñование.txt اÙ
what I should get
Шифрование.txt العربية.txt
if I remove L"%s" I get this
퀠킨톸톄킀킾킲킰킽킸⺵硴⁴�������⺩硴ੴ
can someone explain in detail how to read multibytes characters using ReadFile
