我如何才能知道用户是否已连接到互联网?

问题描述:

是的,我知道! www.codeproject.com中存在很多相同的问题.但是我需要一个标准的API或一些东西来检测连通性.

yes I know! there is a lot of the same question here in www.codeproject.com. But I need a standard API or something to detect the connectivity.

您可以通过包含wininet.h并使用以下代码段来使用InternetGetConnectedState():

You can use InternetGetConnectedState() by including wininet.h and using the following snippet:

<br />#pragma comment(lib,"wininet.lib")<br /> <br />if (InternetGetConnectedState(INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_MODEM,0) == FALSE)<br />{<br />    // Not connected!<br />}<br />else<br />{<br />   // Connected!<br />}<br />



干杯! :)



Cheers! :)


请参见此处.

See here.


查看IsNetworkAlive API

Check out the IsNetworkAlive API