检测网卡是否活动的vc代码
作者:cnfgg 日期:2009-09-10
IsNetworkAlive Function
The IsNetworkAlive function determines whether or not a local system is connected to a network, and identifies the type of network connection, for example, a LAN, WAN, or both.
Syntax
C++
Bool IsNetworkAlive(
__out LPDWORD lpdwFlags
);
Parameters
lpdwFlags [out]
The type of network connection that is available. This parameter can be one of the following values:
NETWORK_ALIVE_LAN
The computer has one or more LAN cards that are active.
NETWORK_ALIVE_WAN
The computer has one or more active RAS connections.
Return Value
TRUE If the last error is 0 and the function returns TRUE, SENS has determined that a local system is connected to a network.
FALSE If the last error is 0 and the function returns FALSE, SENS has determined there is no connection.
检测网卡是否活动的vc代码如下:
头文件
复制内容到剪贴板
程序代码
程序代码#define NETWORK_ALIVE_LAN 0x00000001
#define NETWORK_ALIVE_WAN 0x00000002
#define NETWORK_ALIVE_AOL 0x00000004
typedef BOOL (CALLBACK *ISNETWORKALIVE)(LPDWORD lpdwFlags);
class CCheckNetAlive : public CObject
{
public:
CCheckNetAlive();
virtual ~CCheckNetAlive();
public:
HINSTANCE hinstLib;
ISNETWORKALIVE IsNetworkAlive;
public:
BOOL IsNetAlive();
};
cpp文件
复制内容到剪贴板
程序代码
程序代码CCheckNetAlive::CCheckNetAlive()
{
hinstLib = LoadLibrary("SENSAPI.DLL");
if(hinstLib)
{
IsNetworkAlive=(ISNETWORKALIVE)GetProcAddress(hinstLib, "IsNetworkAlive");
if(IsNetworkAlive==NULL)
{
printf("载入函数IsNetworkAlive失败!");
}
}
else
{
printf("载入库SENSAPI.DLL失败!");
}
}
CCheckNetAlive::~CCheckNetAlive()
{
if(hinstLib)
FreeLibrary(hinstLib);
}
BOOL CCheckNetAlive::IsNetAlive()
{
if(IsNetworkAlive!=NULL)
{
DWORD dwFlag = 0;
BOOL bRes = IsNetworkAlive(&dwFlag);
if(bRes)
{
if((dwFlag&NETWORK_ALIVE_WAN) || (dwFlag&NETWORK_ALIVE_LAN))
return TRUE;
else
return FALSE;
}
else
{
return FALSE;
}
}
return FALSE;
}
评论: 1 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags:
相关日志:
回复
]