求助:GetLastError() == ERROR_IO_PENDING 问题?

xmzh 2006-03-24 09:42:19
boolean serialWrite(HANDLE h, int bytesToWrite,char* buffer,int *bytesWritten)

{

OVERLAPPED os = {0};

int res;


memset(&os,0,sizeof(OVERLAPPED));

os.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

res = WriteFile(h,buffer,bytesToWrite,bytesWritten,&os);

if( fWriteStat == 0 )

{

if( GetLastError() == ERROR_IO_PENDING )

{

while ( GetOverlappedResult(h,&os,numberOfBytesWritten,TRUE) == 0 )

{

dwError=GetLastError();

if( dwError == ERROR_IO_INCOMPLETE )
{
continue;
}
else
{
return FALSE;
}

}

}

}

return TRUE;

}
运行半天就会始终返回false,谁知道怎么回事?
...全文
1757 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmzh 2006-05-11
  • 打赏
  • 举报
回复
不发数据!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
一条晚起的虫 2006-05-11
  • 打赏
  • 举报
回复
while ( GetOverlappedResult(h,&os,numberOfBytesWritten,TRUE) == 0 ) //TRUE --> FALSE

{

dwError=GetLastError();

if( dwError == ERROR_IO_INCOMPLETE )
{
continue;
}
else
{
ClearCommError(,,);
//如果还不行,看看dwError到底是多少,根据dwError大致可以判断一下原因。
return FALSE;
}
xmzh 2006-04-14
  • 打赏
  • 举报
回复
关键是为什么运行一段时间它就不发数据了,端点显示在这个地方,总是返回false
robin_yao 2006-04-12
  • 打赏
  • 举报
回复
ERROR_IO_PENDING
这个本来就不是错误,表示系统还没读完,或者写完!!
BOOL GetOverlappedResult(
HANDLE hFile, // handle to file, pipe, or device
LPOVERLAPPED lpOverlapped, // overlapped structure
LPDWORD lpNumberOfBytesTransferred, // bytes transferred
BOOL bWait // wait option
);

参数
bWait
[in] Specifies whether the function should wait for the pending overlapped operation to be completed. If TRUE, the function does not return until the operation has been completed. If FALSE and the operation is still pending, the function returns FALSE and the GetLastError function returns ERROR_IO_INCOMPLETE.
steed_jet 2006-04-06
  • 打赏
  • 举报
回复
建议在写之前调用ClearCommError;
看看GetLastError返回的错误是什么错误根据提示再改进!
xmzh 2006-03-29
  • 打赏
  • 举报
回复
运行一段时间就返回false,谁知道怎么回事?
xmzh 2006-03-28
  • 打赏
  • 举报
回复
没有改善!a
wlwlxj 2006-03-26
  • 打赏
  • 举报
回复
看看候杰翻译的那本win32多线程,比较不错,讲的详细
anothervip 2006-03-24
  • 打赏
  • 举报
回复
GetOverlappedResult(h,&os,numberOfBytesWritten,TRUE) 把TRUE->FALSE

2,643

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧