The code should work, however your code has issues and errors (
dwBytesWritten and
hFile are undefined). Here is the fixed code.
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;
DWORD dwBytesWritten;
unsigned char BOM[3]{ 0xef, 0xbb, 0xbf };
bErr = WriteFile(hDFile, (LPCVOID)BOM, (DWORD)sizeof(BOM), &dwBytesWritten, NULL);
bErr = WriteFile(hDFile, L"hello - J - こんにちは - abcdefghijklmnopqrstuvwxyz", 90, &NumberOfBytesWritten, NULL);
CloseHandle(hDFile);