如题,WriteFile(m_hCom,sendBuf,dwLength,&length,&osWrite);以后length的值一直为0,这不就表示一个数据都没发出去?writefile之前调用的ClearCommError(m_hCom,&dwErrorFlags,&ComStat);dwErrorFlags的值也一直为0,我不懂这0表示什么,在线等高手解答。

解决方案 »

  1.   

    看MSDN的解释:
    lpNumberOfBytesWritten [out, optional] 
    A pointer to the variable that receives the number of bytes written when using a synchronous hFile parameter. WriteFile sets this value to zero before doing any work or error checking. Use NULL for this parameter if this is an asynchronous operation to avoid potentially erroneous results.This parameter can be NULL only when the lpOverlapped parameter is not NULL.For more information, see the Res section.
      

  2.   

    异步发送if(!WriteFile(m_hCom,sendBuf,dwLength,&length,&osWrite))
    {
    if(GetLastError()==ERROR_IO_PENDING)
    GetOverlappedResult(m_hCom,&m_osWrite,&length,TRUE);
    }
      

  3.   

    //你用的是异步方式,函数不等操作完成就返回了,所以length == 0