ReadFile函数卡住

你在打开文件时用了FILE_FLAG_OVERLAPPED,但是ReadFile中 lpOverlapped传的是NULL。
把FILE_FLAG_OVERLAPPED改成FILE_ATTRIBUTE_NORMAL试试。
================================
打开文件时不用FILE_FLAG_OVERLAPPED,ReadFile的最后一个参数就是NULL。
如果用了FILE_FLAG_OVERLAPPED,则ReadFile的最后一个参数必须是一个OVERLAPPED结构。下面只是一个最简单的例子,一般不是多线程没有必要:
OVERLAPPED overlap;
memset(&overlap, 0, sizeof(overlap));
rc = ReadFile(m_CID_Handle,buf,128,&dwLength &overlap);
if (rc)
{
//the data was read successfully
}
else
{
if (GetLastError() == ERROR_IO_PENDING)
{
WaitForSingleObject(m_CID_Handle,INFINITE);
rc = GetOverlappedResult(m_CID_Handle, &overlap, &dwLength, FALSE);
}
else
{
}
}

你可能感兴趣的:(C++)