It seems that I recently discovered a big fat bug in Windows 7 ultimate 64 Bit.
The weird thing is that I cannot find anything in Google or MSDN about it.
It seems impossible that I am the first to discover a bug in an API so important as WriteFileEx
in an operating system that is on the market since a long time ?!?!?!?
But my code is too simple to be wrong.
Apart from that my code works perfectly on: Windows XP prof 32 Bit, Windows Vista ultimate 32 Bit, Windows 7 ultimate 32 Bit, and it even works on Windows 7 ultimate 64 Bit if compiled as 64 Bit.
The only failure happens on a Windows 7 - 64 Bit if compiled as 32 Bit.
What happens is that the file is written correctly to disk, the completion routine is called, but the completion routine reports that zero bytes have been written and the most weird thing is that the OVERLAPPED
structure has the wrong address and invalid content!!
Can anybody please confirm that this is a bug ?
void WINAPI CompletionRoutine(DWORD u32_ErrorCode, DWORD u32_BytesTransfered,
OVERLAPPED* pk_Overlapped)
{
printf("CompletionRoutine: Transferred: %d Bytes, AddrOverlapped: 0x%X\n",
u32_BytesTransfered, (DWORD_PTR)pk_Overlapped);
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
printf("Compiled as: %d Bit\n", sizeof(DWORD_PTR) == 8 ? 64 : 32);
HANDLE h_File = CreateFileW(L"E:\\Temp\\Test.txt", GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, 0,
CREATE_ALWAYS, 0, 0);
OVERLAPPED k_Over = {0};
printf("Before WriteFileEx AddrOverlapped: 0x%X\n", (DWORD_PTR)&k_Over);
WriteFileEx(h_File, "ABCDEF", 6, &k_Over, CompletionRoutine);
printf("Before SleepEx\n");
SleepEx(1000, TRUE);
printf("Exit\n");
return 0;
}
Here the results: