文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 精品软件 | 下载排行 | 推荐下载 | 免费看大片 | WPS | 杀毒软件
清风网络
首 页 软件下载 网络学院 数码学院
QQ 电脑入门 游戏 操作系统 图形处理 办公软件 媒体动画 精文荟萃 工具软件 网络编程 程序开发 网络技术 认证考试 网站建设 文章专栏
当前位置:清风网络学院程序开发C/C++深入浅出Win32多线程程序设计之综合实例
精品推荐
特别推荐
·C语言编程易犯毛病集合
·C语言编程常见问题解答(目录)
·C#程序开发中的常用函数汇总
·C/C++笔试、面试题目大汇总
·Beej的网络socket编程指南
·socket编程原理
·C语言的常用库函数使用方法分析及用途
·在C语言中如何处理时间和日期
·C++设计模式之Singleton
·VC++动态链接库编程之MFC扩展 DLL
热点TOP10
·进程和线程编程
·C语言编程易犯毛病集合
·打字游戏
·Awk 基础入门:Awk 实例编程
·asp.net中调用javascript函数实现多功能日期控件示例
·C语言编程常见问题解答之常用函数的包含文件(1)
·C# GridView 排序及分页
·C #中的几个线程同步对象方法
·无废话C#设计模式之三:Abstract Factory
·C# DataGridView隔行显示不同的颜色

深入浅出Win32多线程程序设计之综合实例

日期:2008年6月6日 作者: 查看:[大字体 中字体 小字体]



  // Clear buffer
  PurgeComm(port->m_hComm, PURGE_RXCLEAR PURGE_TXCLEAR PURGE_RXABORT PURGE_TXABORT);

  bResult = WriteFile(port->m_hComm, // Handle to COMM Port
    port->m_szWriteBuffer, // Pointer to message buffer in calling finction
    strlen((char*)port->m_szWriteBuffer), // Length of message to send
    &BytesSent, // Where to store the number of bytes sent
    &port->m_ov); // Overlapped structure

  // deal with any error codes
  if (!bResult)
  {
   DWORD dwError = GetLastError();
   switch (dwError)
   {
    case ERROR_IO_PENDING:
    {
     // continue to GetOverlappedResults()
     BytesSent = 0;
     bWrite = FALSE;
     break;
    }
    default:
    {
     // all other error codes
     port->ProcessErrorMessage("WriteFile()");
    }
   }
  }
  else
  {
   LeaveCriticalSection(&port->m_csCommunicationSync);
  }
 } // end if(bWrite)

 if (!bWrite)
 {
  bWrite = TRUE;

  bResult = GetOverlappedResult(port->m_hComm, // Handle to COMM port
   &port->m_ov, // Overlapped structure
   &BytesSent, // Stores number of bytes sent
  TRUE); // Wait flag

  LeaveCriticalSection(&port->m_csCommunicationSync);

  // deal with the error code
  if (!bResult)
  {
   port->ProcessErrorMessage("GetOverlappedResults() in WriteFile()");
  }
 } // end if (!bWrite)

 // Verify that the data size send equals what we tried to send
 if (BytesSent != strlen((char*)port->m_szWriteBuffer))
 {
  TRACE("WARNING: WriteFile() error.. Bytes Sent: %d; Message Length: %d\n",
  BytesSent, strlen((char*)port->m_szWriteBuffer));
 }
}

//
// Character received. Inform the owner
//
void CSerialPort::ReceiveChar(CSerialPort *port, COMSTAT comstat)
{
 BOOL bRead = TRUE;
 BOOL bResult = TRUE;
 DWORD dwError = 0;
 DWORD BytesRead = 0;
 unsigned char RXBuff;

 for (;;)
 {
  // Gain ownership of the comm port critical section.
  // This process guarantees no other part of this program
  // is using the port object.

  EnterCriticalSection(&port->m_csCommunicationSync);

  // ClearCommError() will update the COMSTAT structure and
  // clear any other errors.

  bResult = ClearCommError(port->m_hComm, &dwError, &comstat);

  LeaveCriticalSection(&port->m_csCommunicationSync);

上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] 下一页 




上一篇:C++箴言:理解typename的两个含义

下一篇:C++箴言:谨慎使用多继承

相关文章:
·Photoshop CS3合成实例:人间天堂
·DataList嵌套实例
·Photoshop实例:制作超酷影片画面场景
·综合实例:PS洗衣粉包装设计印刷全攻略
·Photoshop精细抠像实例
·PS初学者实例教程 烫金字的制作
·进程和线程编程
·[综合交流]母矿、矿石、魔法石、召唤石的出处
·[综合]《武林外传》内测账号密码修改指南
·Flash动画制作实例:小野人玩摇滚
相关软件:
·C语言程序设计
·中文版Excel 2003实例与技巧
·CorelDraw12 入门与实例(图文教程 菜鸟先飞系列教材)
·AutoCAD2002入门与实例详解
·Windows环境下32位汇编语言程序设计
·Flash MX 动画制作实例教程
·注册表实例应用视频教程swf
·英语自考-综合英语(一)上册 - 第01讲(全16讲)
·PhotoShop7 设计百例 + 经典实例教程 + 滤镜教学
·AUTOCAD 2002机械设计应用与实例

特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
[打印本页] [关闭窗口] 转载请注明来源:http://www.viphot.com
| 帮助(?) | 版权声明 | 友情连接 | 关于我们 | 信息发布
Copyright 2007 www.viphot.com All Rights Reserved. 鄂ICP备05000083号Powered by:viphot