异步操作

readFile最后一个参数决定如何异步操作

typedef struct _OVERLAPPED {
ULONG_PTR Internal;//请求的错误码
ULONG_PTR InternalHigh;//保存传输成功的字节数
union {
struct {//从哪里开始,两个dword
DWORD Offset;
DWORD OffsetHigh;
} DUMMYSTRUCTNAME;
PVOID Pointer;
} DUMMYUNIONNAME;
HANDLE hEvent;//事件内核对象,handel本质是void*
} OVERLAPPED, *LPOVERLAPPED;
BOOL bRet=ReadFile(hFile, bBuffer, 255, nullptr, &overlapped);
DWORD dwError = GetLastError();
if (!bRet&&dwError==ERROR_IO_PENDING)
{
//请求发送成功
WaitForSingleObject(hFile, INFINITE);//阻塞到请求完成
}

你可能感兴趣的:(异步操作)