I want to place what I read from a utf-8 *.txt file (with Unicode characters in it) to a MessageBox.
(This is a further question after I received useful logic from you to the last question at https://www.codeproject.com/Questions/5335822/Save-file-with-unicode-string-in-old-windows-syste )
As I said in the previous question:
Quote:
If I want to update some software for my uncle's old saw mill machine that has a programmable controller with C, and I want to code it in C or C++98 or in C++03, nothing newer, then how do make the following work for that?
I am doing a test on an old Windows XP Pro 32 bit system with every (at the time of installation) code page installed, and with CodeBlocks 17.12 and GCC of 5.1 . I think that I should be able to code it for the older system with this. [...]
If I can do it all in C then that is OK.
I prefer to do this in C, but if 98 or 03 works that is OK also.
I think that I need to convert from an LPVOID to a const wchar_t* or to a wstring to do this.
For my LPVOID I am using
LPVOID lpBuffer;
const char* pString_from_lpBuffer;
I am reading from the file with
BOOL bErr01 = ReadFile(
HANDLE_Of_File_to_READ, lpBuffer, sizeof(lpBuffer), &nNumberOfBytesToRead, NULL );
Which I created with
HANDLE HANDLE_Of_File_to_READ = CreateFile(TheFile_to_READ, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
Here is where I am:
I am receiving a pointer to a constant of which I do not know the type. I have studied this and I have not found what this type is except that the LPVOID accepts whatever is sent to it. So helpful but not helpful for me to convert. From an unknown constant type to a const wchar_t*.
I want to see, in a MessageBox what the text is that I am reading, including the Unicode characters.
Hours later, I am posting this question.
Thank you.
What I have tried:
const wchar_t* TheFile_to_READ;
TheFile_to_READ = L"utf8_UsingByteOrderMark_C_天堂.txt";
HANDLE HANDLE_Of_File_to_READ;
HANDLE_Of_File_to_READ = CreateFile(TheFile_to_READ, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (HANDLE_Of_File_to_READ == INVALID_HANDLE_VALUE)
{
MessageBox(nullptr, L"CreateFile(HANDLE_Of_File_to_READ) utf8_UsingByteOrderMark_C_天堂.txt failed", L"CreateFile(HANDLE_Of_File_to_READ) utf8_UsingByteOrderMark_C_天堂.txt failed", MB_ICONEXCLAMATION | MB_OK);
}
LPVOID lpBuffer;
const char* pString_from_lpBuffer;
DWORD nNumberOfBytesToRead;
BOOL bErr01;
bErr01 = false;
bErr01 = ReadFile(
HANDLE_Of_File_to_READ,
lpBuffer,
sizeof(lpBuffer),
&nNumberOfBytesToRead,
NULL
);
CloseHandle(HANDLE_Of_File_to_READ);