Quote:
Does this one boolean need to be, or should it be initialized?
This specific Boolean do not need to be initialized because its value is never used in this code.
This code does exactly the same:
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);
The correct principle is:
BOOL bErr;
bErr = 0;
bErr = WriteFile(hFile, (LPCVOID)BOM, (DWORD)sizeof(BOM), &dwBytesWritten, NULL);
if (bErr) ...
No exeption, unless making decisions based on razndom values is not a problem.