The following:
if (!(hFile = CreateFile(...)))
is not how you check for errors.
From the documentation:
If the function fails, the return value is
INVALID_HANDLE_VALUE
. To get extended error information, callGetLastError
.
INVALID_HANDLE_VALUE
is -1
, or 0xFFFFFFFFF
in hex. You need to call GetLastError()
to find out what happened.