Contains information used in asynchronous (or overlapped) input and output (I/O).
包含用在异步输入和输入IO的信息。
定义:
typedef struct _OVERLAPPED { ULONG_PTR Internal; ULONG_PTR InternalHigh; union { struct { DWORD Offset; DWORD OffsetHigh; }; PVOID Pointer; }; HANDLE hEvent; } OVERLAPPED, *LPOVERLAPPED;
Members
-
Internal
-
IO请求的状态码,当一个请求来了,操作系统设置将变量为STATUS_PENDING来暗示这个操作还没有开始。当请求完成了,设置为另一状态。
InternalHigh
-
为IO请求传输的字节数。
Offset
-
开始IO请求文件位置的低位部分。如果不是文件,那必须设为0.
OffsetHigh
-
高位部分
Pointer
-
内部调用,一般设为NULL。
hEvent
-
一个事件句柄将用来设置为激发态,当操作完成后。用户必须初始化这个句柄。这个event可以用来同步一个设备上并发的IO请求。
注意
Any unused members of this structure should always be initialized to zero before the structure is used in a function call. Otherwise, the function may fail and return ERROR_INVALID_PARAMETER.
结构中不用的成员应该被设置为0.
The Offset and OffsetHigh members together represent a 64-bit file position. It is a byte offset from the start of the file or file-like device, and it is specified by the user; the system will not modify these values. The calling process must set this member before passing the OVERLAPPED structure to functions that use an offset, such as the ReadFile or WriteFile(and related) functions.
You can use the HasOverlappedIoCompleted macro to check whether an asynchronous I/O operation has completed ifGetOverlappedResult is too cumbersome for your application.
You can use the CancelIo function to cancel an asynchronous I/O operation.
A common mistake is to reuse an OVERLAPPED structure before the previous asynchronous operation has been completed. You should use a separate structure for each request. You should also create an event object for each thread that processes data. If you store the event handles in an array, you could easily wait for all events to be signaled using the WaitForMultipleObjects function.
For additional information and potential pitfalls of asynchronous I/O usage, see CreateFile, ReadFile, WriteFile, and related functions.
For a general synchronization overview and conceptual OVERLAPPED usage information, see Synchronization and Overlapped Input and Output and related topics.
For a file I/O–oriented overview of synchronous and asynchronous I/O, see Synchronous and Asynchronous I/O.