Click here to Skip to main content
15,885,278 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Writing std::string to a binary file? Pin
Ravi Bhavnani11-Feb-06 6:59
professionalRavi Bhavnani11-Feb-06 6:59 
GeneralRe: Writing std::string to a binary file? Pin
Lord Kixdemp11-Feb-06 7:27
Lord Kixdemp11-Feb-06 7:27 
GeneralRe: Writing std::string to a binary file? Pin
Ravi Bhavnani11-Feb-06 7:33
professionalRavi Bhavnani11-Feb-06 7:33 
GeneralRe: Writing std::string to a binary file? Pin
Lord Kixdemp11-Feb-06 8:08
Lord Kixdemp11-Feb-06 8:08 
GeneralRe: Writing std::string to a binary file? Pin
Ravi Bhavnani11-Feb-06 8:11
professionalRavi Bhavnani11-Feb-06 8:11 
QuestionDetecting Internet connection Pin
Healdp11-Feb-06 0:53
Healdp11-Feb-06 0:53 
AnswerRe: Detecting Internet connection Pin
Taka Muraoka11-Feb-06 2:07
Taka Muraoka11-Feb-06 2:07 
AnswerRe: Detecting Internet connection Pin
bob1697211-Feb-06 2:49
bob1697211-Feb-06 2:49 
Checking the routing table for a default route is the best technique I've come across so far as it does not require checking a URL, pinging an IP address, or other techniques that will not be entirely accurate in all contexts. It also does not invoke any RAS connection dialog boxes which makes it sound like what your looking for.

(You mentioned you cannot get the SDK installed. If you are using VC++ 6.0, you will need the February 2003 SDK or prior installed to use this or to at least get the header and .lib files. Any SDK after this is incompatible with VC++ 6.0 at least without jumping through numerous hoops to get it to work. If you are using VC++ 7.1, the SDK is available on your installation disks)

I got the idea from someone on CodeGuru before they upgraded their website and lost all the legacy comments. Unfortunately, I do not know the name of the person who passed on the idea so I can't give credit where credit is do but I'll pass it on...

The function to use is GetIpForwardTable(). I use a timer to periodically check for connectivity and update my status indicator accordingly. There is a slight delay maybe a second or two if you unplug the cable or plug it in (assuming your timer is set to fire every second). No noticeable delay when disabling the connection using a GUI tool.

Don't forget to include in StdAfx.h...
#include <iphlpapi.h> // For Routing table query

And make sure to reference the Platform SDK lib file...
iphlpapi.lib

BOOL CNetworkConnectionDlg::IsInternetAvailable(void)
{
MIB_IPFORWARDTABLE * pRoutingTable;
DWORD dwBufferSize=0;
BOOL bIsInternetAvailable=FALSE;
DWORD dwResult;
DWORD dwIndex;
DWORD dwRowCount;

// Get the required buffer size
GetIpForwardTable(NULL,&dwBufferSize,FALSE);
pRoutingTable=(MIB_IPFORWARDTABLE*)new BYTE[dwBufferSize];

// Attempt to fill buffer with routing table information
dwResult=GetIpForwardTable(pRoutingTable,&dwBufferSize,FALSE);

if (dwResult==NO_ERROR) {
dwRowCount=pRoutingTable->dwNumEntries; // Get row count

// Look for default route to gateway
for (dwIndex=0;dwIndex<dwRowCount;dwIndex++) {
if (pRoutingTable->table[dwIndex].dwForwardDest==0) { // Default route designated by 0.0.0.0 in table
bIsInternetAvailable=TRUE; // Found it
break; // Short circuit loop
}
}
}

delete pRoutingTable; // Clean up. Just say "No" to memory leaks

return bIsInternetAvailable;
}
GeneralRe: Detecting Internet connection Pin
Healdp11-Feb-06 4:04
Healdp11-Feb-06 4:04 
GeneralRe: Detecting Internet connection Pin
bob1697211-Feb-06 5:05
bob1697211-Feb-06 5:05 
GeneralRe: Detecting Internet connection Pin
Healdp12-Feb-06 1:22
Healdp12-Feb-06 1:22 
GeneralRe: Detecting Internet connection Pin
bob1697211-Feb-06 5:26
bob1697211-Feb-06 5:26 
GeneralRe: Detecting Internet connection Pin
Healdp11-Feb-06 5:45
Healdp11-Feb-06 5:45 
GeneralRe: Detecting Internet connection Pin
bob1697211-Feb-06 6:13
bob1697211-Feb-06 6:13 
GeneralRe: Detecting Internet connection Pin
Sunil P V7-Mar-07 19:35
Sunil P V7-Mar-07 19:35 
AnswerRe: Detecting Internet connection Pin
PJ Arends11-Feb-06 6:10
professionalPJ Arends11-Feb-06 6:10 
AnswerRe: Detecting Internet connection Pin
Ravi Bhavnani11-Feb-06 7:01
professionalRavi Bhavnani11-Feb-06 7:01 
AnswerRe: Detecting Internet connection Pin
Nish Nishant11-Feb-06 7:53
sitebuilderNish Nishant11-Feb-06 7:53 
QuestionAdd .lib library to Visual C++ project? Pin
Nick_Kisialiou11-Feb-06 0:05
Nick_Kisialiou11-Feb-06 0:05 
AnswerRe: Add .lib library to Visual C++ project? Pin
Stephen Hewitt11-Feb-06 0:15
Stephen Hewitt11-Feb-06 0:15 
GeneralRe: Add .lib library to Visual C++ project? Pin
Nick_Kisialiou11-Feb-06 10:00
Nick_Kisialiou11-Feb-06 10:00 
QuestionC++ persistence framework Pin
eusto10-Feb-06 23:43
eusto10-Feb-06 23:43 
AnswerRe: C++ persistence framework Pin
Stephen Hewitt11-Feb-06 0:19
Stephen Hewitt11-Feb-06 0:19 
AnswerRe: C++ persistence framework Pin
Kevin McFarlane11-Feb-06 1:18
Kevin McFarlane11-Feb-06 1:18 
AnswerRe: C++ persistence framework Pin
Ravi Bhavnani11-Feb-06 7:02
professionalRavi Bhavnani11-Feb-06 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.