Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following. It shows up correctly in Microsoft NotePad. It does not show up correctly in Microsoft Wordpad.

Using CodeBlocks 17.12 / MinGW with GCC 5.1 / 32 bit Microsoft Windows XP Pro sp2.

__________

When I open the txt file with Apache OpenOffice Writer 4 I get :
h#e#l#l#o# #-# #J# #-# #S0�0k0a0o0 #-# #a#b#c#d#e#f#g#h#i#j#k#l#m#n#o#p#q#r#s#t#u#v#w#x#y#
WRONG and Not usable.

And why all the # ? Why not just give me the Unicode text correctly?

__________

When I open the txt file with Microsoft Notepad I get :
hello - J - こんにちは - abcdefghijklmnopqrstuvwxy

RIGHT and Usable.

My code:

What I have tried:

What I have tried:

HANDLE hDFile = CreateFile(L"utf8_UsingByteOrderMark_C_天堂.txt", GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

DWORD NumberOfBytesWritten;

BOOL bErr = 0;

unsigned char BOM[3]{ 0xef, 0xbb, 0xbf };

bErr = WriteFile(hFile, (LPCVOID)BOM, (DWORD)sizeof(BOM), &dwBytesWritten, NULL);

bErr = WriteFile(hDFile, L"hello - J - こんにちは - abcdefghijklmnopqrstuvwxyz", 90, &NumberOfBytesWritten, NULL);

CloseHandle(hDFile);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900