This code, which I have no control over, reads a file using overlapped I/O:
// Read file asynchronously
HANDLE hFile = CreateFile(..., FILE_FLAG_OVERLAPPED, ...);
BYTE buffer[10];
OVERLAPPED oRead = { 0 };
ReadFile(hFile, buffer, 10, NULL, &oRead);
// Do work while file is being read
...
// Wait for read to finish
WaitForSingleObject(hFile, INFINITE);
// ReadFile has finished
// buffer now contains data which can be used
...
In another thread (actually in an API hook of ReadFile), I need to signal the hFile
to unblock the WaitForSingleObject
. Normally Windows (or the device driver handling the ReadFile
) does this, but I need to simulate it.
None of the APIs I found that normally do this work with hFile
, including ReleaseMutex
, ReleaseSemaphore
, and SetEvent
. They all return Error 6 (handle is invalid). Is there an API that works with a file, named pipe, or communications device?
I know it is not recommended to WaitForSingleObject(hFile)
, but the above code is a given, and I need to work with it. Thanks!