none
如何判断网线的插拔状态? RRS feed

  • 问题

  • 我现在用函数InternetGetConnectedState来判断,发现并不准确,有时网线明明是插好的,但是该函数还是返回FALSE.
    2014年12月5日 6:00

答案

  • 你好:

          你可以试一下IsNetworkAlive()函数。详细信息文档:http://msdn.microsoft.com/en-us/library/windows/desktop/aa377522(v=vs.85).aspx

    #include "iostream"
    #include "windows.h"
    #include <Sensapi.h>
    using namespace std;
    #pragma comment(lib, "Sensapi.lib")
    
    int main()
    {
    	DWORD dw;
    	if (!IsNetworkAlive(&dw))
    	{
    		// error or no connection
    		DWORD const e = GetLastError();
    		if (e == ERROR_SUCCESS)
    		{
    			// no connection
    		}
    		else
    		{
    			// error
    		}
    	}
    	else
    	{
    		// local system is connected to network
    		cout << "local system is connected to network" << endl;
    	}
    
    }
    希望对你有帮助。

    Shu Hu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年12月8日 7:37

全部回复

  • 网络属于局域网,没有连接互联网,也没有网关。
    2014年12月5日 6:07
  • 你好:

          你可以试一下IsNetworkAlive()函数。详细信息文档:http://msdn.microsoft.com/en-us/library/windows/desktop/aa377522(v=vs.85).aspx

    #include "iostream"
    #include "windows.h"
    #include <Sensapi.h>
    using namespace std;
    #pragma comment(lib, "Sensapi.lib")
    
    int main()
    {
    	DWORD dw;
    	if (!IsNetworkAlive(&dw))
    	{
    		// error or no connection
    		DWORD const e = GetLastError();
    		if (e == ERROR_SUCCESS)
    		{
    			// no connection
    		}
    		else
    		{
    			// error
    		}
    	}
    	else
    	{
    		// local system is connected to network
    		cout << "local system is connected to network" << endl;
    	}
    
    }
    希望对你有帮助。

    Shu Hu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年12月8日 7:37
  •        还是不准确,不知道怎么回事,有时候发送一会数据判断就正确了。
    2014年12月9日 3:41