I have opened a file using
HANDLE handle=
CreateFileW(
fileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
FILE_FLAG_OVERLAPPED, NULL);
The file handle is then used for asynchronous read operations:
ReadFile(handle, buffer, 1, NULL, &overlapped);
This works. However, I want to do a synchronous write now. WriteFile
documentation states that
If hFile was opened with FILE_FLAG_OVERLAPPED, the following conditions are in effect:
• The lpOverlapped parameter must point to a valid and unique OVERLAPPED structure, otherwise the function can incorrectly report that the write operation is complete.
When the lpOverlapepd
parameter is omitted, ERROR_INVALID_PARAMETER
is returned by GetLastError()
. Opening two handles, one for reading and one for writing does also not work since the second handle produces a ERROR_ACCESS_DENIED
error.
How can I open the file for asynchronous reads and synchronous writes? I don't want to increase code complexity unnecessarily.