BOOL ReadPipe(HANDLE hPipe, PVOID lpBuffer, UINT nSize, UINT MaxTime) { BOOL bRet = FALSE; DWORD dwOpt, dwTick; if (MaxTime != -1) dwTick = GetTickCount(); while (TRUE) { Sleep(100); if (PeekNamedPipe(hPipe, NULL, 0, NULL, &dwOpt, NULL)) { if (dwOpt >= nSize) { bRet = ReadFile(hPipe, lpBuffer, nSize, &dwOpt, NULL); break;//while } } if (MaxTime != -1) { if (GetTickCount() - dwTick > MaxTime) break;//while } } return bRet; }