Click to See Complete Forum and Search --> : Internet connection handling
shah_shweta
June 1st, 2004, 09:39 AM
I want to check if my machine is connected to internet.It can be any of the following ways,
1.Using dial-up
2.Through LAN
2.Broadband connection
Please can anybody guide me how to go about this.
Also once i get to know that mahcine is offline, i want to connect to internet using deafult ISP connection configured for modem.
TIA
Regards,
Shweta
NoHero
June 1st, 2004, 11:14 AM
#include "Ras.h"
#pragma comment(lib, "rasapi32.lib")
// Returns != 0 if the computer is connected to the internet. 0 otherwise.
int IsConnected ( void )
{
RASENTRYNAME ras[2];
DWORD dwSize = sizeof(ras);
DWORD dwReturn = 0;
for ( int i = 0; i < 2; i++ )
{
ras[i].dwSize = sizeof(RASENTRYNAME);
}
if ( !RasEnumEntries(NULL, NULL, ras, &dwSize, &dwReturn) )
{
if ( dwReturn > 0 )
return 1;
else
return 0;
}
return 0;
}
hope this works
This checks if the machine is connected ... See the "RasDial" and "RasDialDlg" for a way to connect to the internet. It may too big for an example here ...
Regards
nohero
Bond
June 1st, 2004, 11:30 AM
Another way...
#include <wininet.h>
// Link with WININET.LIB or uncomment the following line:
// #pragma comment(lib, "wininet.lib")
BOOL ConnectedToNet()
{
DWORD dw;
return InternetGetConnectedState(&dw, 0);
}
If you attempt to use any of the wininet functions, and a connection to the interent does not exist, it will attempt to connect using the default connection.
NoHero
June 1st, 2004, 11:41 AM
Ok, you won ... :D ...
I have never used the Internet* functions though ... Is the wininet.dll accessable @ windows 9X ??
ng
Bond
June 1st, 2004, 12:04 PM
:)
I always take the lazy route!
Yep, wininet functions should be available from Windows 9x.
shah_shweta
June 1st, 2004, 11:28 PM
Instead of RAS i wanted to use WinInet functions?
Is it possible?
shah_shweta
June 1st, 2004, 11:40 PM
I am using WinInet.dll for checking the internet connection functionality.However, while compiling the below code , i am getting following error.
" error C2065: 'INTERNET_CONNECTION_CONFIGURED' : undeclared identifier Error executing cl.exe."
I have included WinInet.h in the file and linked Wininet.lib .
I have VC++ 6.0 with SP6 and i am working on WinNT
/*************/
DWORD lpdwFlags;
BOOL bRetVal;
bRetVal = InternetGetConnectedState(&lpdwFlags, 0);
if ( lpdwFlags & INTERNET_CONNECTION_CONFIGURED )
cout << "INTERNET_CONNECTION_CONFIGURED" << endl;
if ( lpdwFlags & INTERNET_CONNECTION_LAN )
cout << "INTERNET_CONNECTION_LAN " << endl;
if ( lpdwFlags & INTERNET_CONNECTION_MODEM )
cout << "INTERNET_CONNECTION_MODEM " << endl;
/* if ( lpdwFlags & INTERNET_CONNECTION_OFFLINE )
cout << "INTERNET_CONNECTION_OFFLINE " << endl;*/
if ( lpdwFlags & INTERNET_CONNECTION_PROXY )
cout << "INTERNET_CONNECTION_PROXY " << endl;
/******************************/
It seems that INTERNET_CONNECTION_CONFIGURED doesn't exist in the older WININET.H files.
I checked WinInet.h and it does not have this entry in it.
1. How do i know which version of SDK i am using ?
2.Which version Of SDk has this in it? I installed latest Internet development SDK ..but it was of no use.
3.In which SDK is WinInet implemented?
Bond
June 2nd, 2004, 10:03 AM
The Core Platform SDK. This thread looks familiar... :)
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
usman999_1
June 4th, 2004, 09:06 AM
Originally posted by NoHero
#include "Ras.h"
#pragma comment(lib, "rasapi32.lib")
// Returns != 0 if the computer is connected to the internet. 0 otherwise.
int IsConnected ( void )
{
RASENTRYNAME ras[2];
DWORD dwSize = sizeof(ras);
DWORD dwReturn = 0;
for ( int i = 0; i < 2; i++ )
{
ras[i].dwSize = sizeof(RASENTRYNAME);
}
if ( !RasEnumEntries(NULL, NULL, ras, &dwSize, &dwReturn) )
{
if ( dwReturn > 0 )
return 1;
else
return 0;
}
return 0;
}
hope this works
This checks if the machine is connected ... See the "RasDial" and "RasDialDlg" for a way to connect to the internet. It may too big for an example here ...
Regards
nohero
This is incorrect. According to MSDN...
The RasEnumEntries function lists all entry names in a remote access phone book.
Regards,
Usman.
NoHero
June 4th, 2004, 11:08 AM
Yep ... I seee "RasEnumConnections" (or something like that) supposed to be the right function, sorry for this freakin' mistake ...
ng
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.