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);//阻塞到請求完成
}