码迷,mamicode.com
首页 > Windows程序 > 详细

VC网络连接判断API

时间:2014-10-18 16:42:36      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   for   sp   div   on   

bool isConnect;  
DWORD dw;  
isConnect = ::IsNetworkAlive(&dw);

if(isConnect)  
  cout << "IsNetworkAlive连接" <<endl;  
else  
  cout << "IsNetworkAlive未连接" <<endl;   
cout<< "---------------------------------" <<endl;  

//dw和dw2标识,可判断本机是以什么方式连接网络。如:代理、拨号等

DWORD dw2;  
bool ret = InternetGetConnectedState(&dw2, 0);  
if (ret)  
  cout << "InternetGetConnectedState连接" <<endl;  
else  
  cout << "InternetGetConnectedState未连接" <<endl;  
cout<< "**********************************"  <<endl;  
     
//FLAG_ICC_FORCE_CONNECTION不可少;当该网络连接地址链接不通时,该API需ping一段时间(1~2分钟)
      bool bConnected = InternetCheckConnection(_T("http://www.baidu.com"), FLAG_ICC_FORCE_CONNECTION, 0);
if (bConnected)  
  cout << "InternetCheckConnection连接" <<endl;  
else  
  cout << "InternetCheckConnection未连接" <<endl;  
cout<< "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"  <<endl;  

 

VC网络连接判断API

标签:style   blog   http   color   io   for   sp   div   on   

原文地址:http://www.cnblogs.com/zw-h/p/4033190.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!