C++Ping一个IP地址的例子

上传者: haha_0011 | 上传时间: 2021-06-09 11:43:22 | 文件大小: 15KB | 文件类型: RAR
=========================================== 使用方法: 1、引入以下4个文件到项目: ping.h ping.cpp PingThread.h PingThread.cpp 2、在StdAfx.h中加入以下代码: #include // MFC socket extensions #define WM_MSG_STATUS WM_USER + 0x0100 #define WM_PING_END WM_USER + 0x0101 // string message allocator for posting messages between windows... static char* AllocBuffer(CString strMsg) { int nLen = strMsg.GetLength(); char *pBuffer = new char[nLen+1]; strcpy(pBuffer,(const char*)strMsg); ASSERT(pBuffer != NULL); return pBuffer; } 3、定义一个变量: CPingThread m_pingThread; 4、定义两个消息响应(WM_MSG_STATUS, WM_PING_END): LRESULT OnStatus(WPARAM wParam, LPARAM lParam); LRESULT OnPingEnd(WPARAM wParam, LPARAM lParam); 5、调用: m_pingThread.StartPing(5, strIPAddr, m_hWnd); 注1:参数5表示ping 5次,实际应用中随意; 6、分析结果 每ping 1次,OnStatus都会收到结果消息,如 失败返回:Request Timed Out 成功返回:Reply[n] from: 192.168.1.109: bytes=32 time=0ms TTL=64 注2:其中n 表示ping的索引(它不重要) 注3:可以在文件ping.cpp修改返回消息(void CPing::Ping(UINT nRetries,LPCSTR pstrHost,HWND hWnd))

文件下载

资源详情

[{"title":"( 17 个子文件 15KB ) C++Ping一个IP地址的例子","children":[{"title":"PingDemo","children":[{"title":"ping.h <span style='color:#111;'> 1.52KB </span>","children":null,"spread":false},{"title":"PingDemoDlg.h <span style='color:#111;'> 1.52KB </span>","children":null,"spread":false},{"title":"PingThread.cpp <span style='color:#111;'> 1.76KB </span>","children":null,"spread":false},{"title":"res","children":[{"title":"PingDemo.ico <span style='color:#111;'> 1.05KB </span>","children":null,"spread":false},{"title":"PingDemo.rc2 <span style='color:#111;'> 400B </span>","children":null,"spread":false}],"spread":true},{"title":"PingDemoDlg.cpp <span style='color:#111;'> 4.72KB </span>","children":null,"spread":false},{"title":"PingDemo.rc <span style='color:#111;'> 5.16KB </span>","children":null,"spread":false},{"title":"PingThread.h <span style='color:#111;'> 818B </span>","children":null,"spread":false},{"title":"PING.cpp <span style='color:#111;'> 5.34KB </span>","children":null,"spread":false},{"title":"StdAfx.cpp <span style='color:#111;'> 210B </span>","children":null,"spread":false},{"title":"resource.h <span style='color:#111;'> 777B </span>","children":null,"spread":false},{"title":"PingDemo.cpp <span style='color:#111;'> 2.13KB </span>","children":null,"spread":false},{"title":"StdAfx.h <span style='color:#111;'> 1.43KB </span>","children":null,"spread":false},{"title":"PingDemo.dsw <span style='color:#111;'> 539B </span>","children":null,"spread":false},{"title":"PingDemo.h <span style='color:#111;'> 1.31KB </span>","children":null,"spread":false},{"title":"PingDemo.dsp <span style='color:#111;'> 4.34KB </span>","children":null,"spread":false},{"title":"ReadMe.txt <span style='color:#111;'> 1.38KB </span>","children":null,"spread":false}],"spread":false}],"spread":true}]

评论信息

  • boyhs1 :
    挺不错的一段代码,学习了!
    2019-02-19
  • u012820623 :
    说明比较详细,可以学习
    2018-10-09

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明