I have read that lpNumberOfBytesWritten (the PDWORD) as it is used by
WINBASEAPI BOOL WINAPI WriteFile(HANDLE,PCVOID,DWORD,PDWORD,LPOVERLAPPED);
is automatically adjusted per value by the WriteFile process.
In the following code I would like to know if the CloseHandle(hDFile); tells the program to clear &NumberOfBytesWritten and remove it from memory automatically. Or, should I clear it before or after closing the file handle?
I create it with DWORD NumberOfBytesWritten;. Is it still there? Is it taking up space holding the number of bytes written. Should I put this entire bit of code into a function to ensure that it is cleared and gone?
Please explain with your answer.
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 bErr2 = 0;
unsigned char BOM2[3]{ 0xef, 0xbb, 0xbf };
bErr2 = WriteFile(hFile, (LPCVOID)BOM2, (DWORD)sizeof(BOM2), &dwBytesWritten, NULL);
bErr2 = WriteFile(hDFile, L"hello - J - こんにちは - abcdefghijklmnopqrstuvwxyz", 90, &NumberOfBytesWritten, NULL);
CloseHandle(hDFile);