The MSDN documentation for lpNumberOfBytesTransferred in
GetOverlappedResult() says:
BOOL WINAPI GetOverlappedResult(
__in HANDLE hFile,
__in LPOVERLAPPED lpOverlapped,
__out LPDWORD lpNumberOfBytesTransferred,
__in BOOL bWait
);
>>> lpNumberOfBytesTransferred
"A pointer to a variable that receives the number of bytes that were
actually transferred by a read or *write* operation. For a
DeviceIoControl operation, this is the number of bytes of output data
returned by the device driver."
Now, for the life of me, I just don't seem to understand a very basic
issue here:
What is that mystical "the number of bytes of output data returned by
the device driver" when doing a WRITE operation (via a DeviceIoControl
call)?
Case in question: I wrote a driver that responds to DeviceIoControl()
commands, supporting overlapped I/O in both read and write directions.
With read I have no problems. However, with write, I just don't seem
to get the crux of this lpNumberOfBytesTransferred (or
IoStatus.Information in the driver).
In my driver, when I do:
pIRP->IoStatus.Information =
actualNumberWritten; // 0 <= int <= 512
The GetOverlappedResult() call on the user mode side (the application
that uses the driver) crashes the program!
But when I do:
pIRP->IoStatus.Information =
pIRPStack->Parameters.DeviceIoControl.OutputBufferLength;
The program doesn't crash.
Now... I thought that, just as the GetOverlappedResult() documentation
says, IoStatus.Information should return "the number of bytes that
were actually transferred by a write operation".
So what's going on here?
Why must IoStatus.Information, on a DeviceIoControl *write* operation,
return the size of the output buffer instead of "the number of bytes
that were actually transferred by a write operation"?
What am I missing here?
Thanks,
Don