Hello, I am hooking ReadFile() and the caller is basically doing something like:
Code: Select all
// Start reading file asynchronously
HANDLE hFile = CreateFile(..., FILE_FLAG_OVERLAPPED, ...);
BYTE bReadBuffer[10];
OVERLAPPED oRead = { 0 };
ReadFile(hFile, bReadBuffer, 10, NULL, &oRead);
// Thread continues to do work while file is being read
...
// Wait for read to finish
WaitForSingleObject(hFile, INFINITE);
// ReadFile has finished
// bReadBuffer now contains data which can be used
...
In my API hook of ReadFile, I need to signal the caller the read is done. But I don't know of an API that will signal a File handle being WaitForSingleObject()'ed. I've tried ReleaseMutex, ReleaseSemaphore (with a count of 1), and SetEvent, and all have failed with Error 6 (handle is invalid). These are the API's Jeffrey Richter in his book
Windows Via C/C++ says are called by SignalObjectAndWait(). What other API's work to release a handle kernel object, and which one works with a handle returned by CreateFile?
Thanks for any help,
David