查询网络状态
BOOL InternetGetConnectedState(
__out LPDWORD lpdwFlags,
__in DWORD dwReserved
);
第一个参数参考一下值:
|
Local system uses a local area network to connect to the Internet. |
|
Local system uses a modem to connect to the Internet. |
|
No longer used. |
|
Local system is in offline mode. |
|
Local system uses a proxy server to connect to the Internet. |
第二个参数一直是零
例子1
DWORD flags;
int tries = 0;
while (InternetGetConnectedState(&flags,0) == FALSE) {
tries++;
Sleep(1000);
if (tries >= 10) {
return 1;
}
}
例子2
#include <windows.h>
#include <Wininet.h>
#pragma comment (lib,"Wininet")
int main(int argc, char* argv[])
{
DWORD flags=INTERNET_CONNECTION_LAN;
int tries = 0;
BOOL repare =InternetGetConnectedState(&flags,0);
if (!repare)
{
printf("no good");
}
return 0;
}
Wininet.h
Wininet.lib
Wininet.dll
用来检查网络连接使用
本文详细介绍了Windows平台下的网络状态检测API——InternetGetConnectedState的使用方法,包括参数解释及两个示例代码,帮助开发者判断本地系统是否在线及连接方式。
577

被折叠的 条评论
为什么被折叠?



