The call to SetFilePointer()
is unrequired as the subsequent WriteFile()
call will write data after the data written by the first WriteFile()
: remove the call to SetFilePointer()
.
The call to SetFilePointer()
is moving the file pointer dwWritten
bytes beyond its current location, and the current location is at the end of the data just written.
Check result of WriteFile()
to ensure data was successfully written and it is important to include the value of GetLastError()
, or its description using FormatMessage()
, in any error messages so the actual cause of the failure is known:
if(hFile==INVALID_HANDLE_VALUE)
{
char error_msg[128];
sprintf(error_msg, "Could not create/open a file: %d", GetLastError());
MessageBox(0,error_msg,"Error",16);
return 0;
}