Article View: borland.public.cppbuilder.nativeapi
Article #12822Re: API Call To Detect Network is offline
From: PaoloItaly
Date: Fri, 14 Nov 2003 08:54
Date: Fri, 14 Nov 2003 08:54
113 lines
3562 bytes
3562 bytes
#include "iphelper.h"
#include "Iptypes.h"
#include "Ipexport.h"
#include "Iphlpapi.h"
void fm(DWORD error, HWND wnd)
{
char *lpMsgBuf;
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default
language
(LPTSTR) &lpMsgBuf,
0,
NULL);
// Display the string.
::MessageBox(wnd, lpMsgBuf, "Internet Protocol Helper", MB_OK);
// Free the buffer.
::LocalFree(lpMsgBuf);
::SetLastError(0);
}
char* getAdapterType(UINT type)
{
switch (type)
{
case MIB_IF_TYPE_OTHER:
return "Unknown";
case MIB_IF_TYPE_ETHERNET:
return "Ethernet";
case MIB_IF_TYPE_TOKENRING:
return "Token ring";
case MIB_IF_TYPE_FDDI:
return "FDDI";
case MIB_IF_TYPE_PPP:
return "PPP";
case MIB_IF_TYPE_LOOPBACK:
return "Loop Back";
case MIB_IF_TYPE_SLIP:
return "SLIP";
}
return "Unknown";
}
char* getAdapterStatus(DWORD status)
{
switch (status)
{
case MIB_IF_OPER_STATUS_NON_OPERATIONAL:
return "NON_OPERATIONAL";
case MIB_IF_OPER_STATUS_UNREACHABLE:
return "UNREACHABLE";
case MIB_IF_OPER_STATUS_DISCONNECTED:
return "DISCONNECTED";
case MIB_IF_OPER_STATUS_CONNECTING:
return "CONNECTING";
case MIB_IF_OPER_STATUS_CONNECTED:
return "CONNECTED";
case MIB_IF_OPER_STATUS_OPERATIONAL:
return "OPERATIONAL";
}
return "Unknown";
}
DWORD ret, cnt;
PMIB_IFTABLE pIfTable = NULL;
PMIB_IFROW next;
ULONG pdwSize = 0;
ret = ::GetIfTable(pIfTable, &pdwSize, false);
if (ret == ERROR_INSUFFICIENT_BUFFER)
{
if ((pIfTable = (PMIB_IFTABLE)malloc(pdwSize)) != NULL)
{
ret = ::GetIfTable(pIfTable, &pdwSize, false);
if (ret == NO_ERROR)
{
for (cnt=0; cnt < pIfTable->dwNumEntries ;cnt ++)
{
next = &pIfTable->table[cnt];
getAdapterType(next->dwType);
getAdapterStatus(next->dwOperStatus);
}
}
else
fm(ret, this->Handle);
free(pIfTable);
}
}
else
fm(ret, this->Handle);
compile this code and have a look at the returned string
of this function getAdapterStatus(next->dwOperStatus);
Good luck
"Helcio Mayor" <HelcioLiza@mayorgroves.fsnet.co.uk> ha scritto nel messaggio
news:3fb3ffd9$1@newsgroups.borland.com...
> Hi guys,
> Anyone knows call back or API call that would detect when say the network
> cable is
> pulled out ?
> Many thanks for you time
>
>
Technical Details
Message-ID:
<3fb49881$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fb3ffd9$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ffb798a39f772144 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-11-14 01:09:30 PST From: "PaoloItaly" <paolo@sirius-es.it> Newsgroups: borland.public.cppbuilder.nativeapi References: <3fb3ffd9$1@newsgroups.borland.com> Subject: Re: API Call To Detect Network is offline Date: Fri, 14 Nov 2003 09:54:58 +0100 Lines: 115 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4927.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200 NNTP-Posting-Host: 81.112.124.34 Message-ID: <3fb49881$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1068800129 81.112.124.34 (14 Nov 2003 00:55:29 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail