参考网页:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684342(v=vs.85).aspx
Contains information used in asynchronous (or overlapped) input and output (I/O).
typedef struct _OVERLAPPED {
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
union {
struct {
DWORD Offset;
DWORD OffsetHigh;
};
PVOID Pointer;
};
HANDLE hEvent;
} OVERLAPPED, *LPOVERLAPPED;
OVERLAPPED structure
Contains information used in asynchronous (or overlapped) input and output (I/O).
Syntax
C++
typedef struct _OVERLAPPED {
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
union {
struct {
DWORD Offset;
DWORD OffsetHigh;
};
PVOID Pointer;
};
HANDLE hEvent;
} OVERLAPPED, *LPOVERLAPPED;
Members
Internal
这个成员用来保存已处理的I/O请求的错误码.
The status code for the I/O request. When the request is issued, the system sets this member to STATUS_PENDING to indicate that the operation has not yet started. When the request is completed, the system sets this member to the status code for the completed request.
The Internal member was originally reserved for system use and its behavior may change.
InternalHigh
当异步I/O请求完成的时候,这个成员用来保存已传输的字节数。
The number of bytes transferred for the I/O request. The system sets this member if the request is completed without errors.
The InternalHigh member was originally reserved for system use and its behavior may change.
Offset
The low-order portion of the file position at which to start the I/O request, as specified by the user.
This member is nonzero only when performing I/O requests on a seeking device that supports the concept of an offset (also referred to as a file pointer mechanism), such as a file. Otherwise, this member must be zero.
For additional information, see Remarks.
OffsetHigh
The high-order portion of the file position at which to start the I/O request, as specified by the user.
This member is nonzero only when performing I/O requests on a seeking device that supports the concept of an offset (also referred to as a file pointer mechanism), such as a file. Otherwise, this member must be zero.
For additional information, see Remarks.
Pointer
Reserved for system use; do not use after initialization to zero.
hEvent
event的句柄,当操作完成的时候,这个event会被设置。
用户必须初始化这个变量为0,或者是在将这个结构体传送给任何overlapped 函数之前,使用CreateEvent函数创建一个一个有效的event 句柄。
这个event可以用来同步IO请求。
ReadFile 和 WriteFile 函数会设置这个event 句柄为 没有信号的状态,然后开始I/O操作。当操作完成之后,句柄被设置为有信号状态。
函数GetOverlappedResult 和通过等待函数会复位 具有自动复位属性的event为无信号状态。
所以需要用一个手动复位的event。
如果使用一个自动复位的event,你的应用
Functions such as GetOverlappedResult and the synchronization wait functions reset auto-reset events to the nonsignaled state. Therefore, you should use a manual reset event; if you use an auto-reset event, your application can stop responding if you wait for the operation to complete and then call GetOverlappedResult with the bWait parameter set to TRUE.