Question

Why does GetOverlappedResult need a file handle?

It seems like WaitForSingleObject(overlapped->hEvent) should be enough to wait on the event so that the overlapped I/O finishes, so what does GetOverlappedResult use the file handle for?

Was it helpful?

Solution

The remarks section of the documentation appears to explain when hFile is needed:

If the hEvent member of the OVERLAPPED structure is NULL, the system uses the state of the hFile handle to signal when the operation has been completed. Use of file, named pipe, or communications-device handles for this purpose is discouraged. It is safer to use an event object because of the confusion that can occur when multiple simultaneous overlapped operations are performed on the same file, named pipe, or communications device. In this situation, there is no way to know which operation caused the object's state to be signaled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top