od0
asked on
Check if online
Is there some easy way to check if you are online from a program made in Visual C++?
You can use the Remote Access Service (RAS) function RasEnumConnections to check if there are any Dial-Up Networking connections.
ASKER
Can you please specify how to use the RasEnumConnections command?
I can't make it work...
I can't make it work...
// return value of RAS functions
DWORD dwRet;
// get the number of connections
DWORD dwSizeBuf = 0, dwNumConnections = 0;
::RasEnumConnections(NULL, &dwSizeBuf, &dwNumConnections);
// enumerate the connections
if (dwNumConnections != 0)
{
// allocate the buffer
LPBYTE lpbyBuf = new BYTE[dwSizeBuf];
// enumerate the connections
LPRASCONN lpConn = reinterpret_cast<LPRASCONN >(lpbyBuf) ;
lpConn->dwSize = sizeof(RASCONN);
if ((dwRet = ::RasEnumConnections(lpCon n, &dwSizeBuf, &dwNumConnections)) != 0)
// DISPLAYERROR(dwRet);
else
for (DWORD dwi = 0; dwi < dwNumConnections; dwi++)
{
// each connection handle is lpConn[dwi].hrasconn
}
// free the buffer
delete []lpbyBuf;
}
DWORD dwRet;
// get the number of connections
DWORD dwSizeBuf = 0, dwNumConnections = 0;
::RasEnumConnections(NULL,
// enumerate the connections
if (dwNumConnections != 0)
{
// allocate the buffer
LPBYTE lpbyBuf = new BYTE[dwSizeBuf];
// enumerate the connections
LPRASCONN lpConn = reinterpret_cast<LPRASCONN
lpConn->dwSize = sizeof(RASCONN);
if ((dwRet = ::RasEnumConnections(lpCon
// DISPLAYERROR(dwRet);
else
for (DWORD dwi = 0; dwi < dwNumConnections; dwi++)
{
// each connection handle is lpConn[dwi].hrasconn
}
// free the buffer
delete []lpbyBuf;
}
ASKER
Well, it still doesn't seems to work. When I compile my program I get a Linking error. It looks like this:
TestDlg.obj : error LNK2001: unresolved external symbol _RasGetConnectStatusA@8.
What am I doing wrong?
TestDlg.obj : error LNK2001: unresolved external symbol _RasGetConnectStatusA@8.
What am I doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, link with rasapi32.lib. (menu Project/Settings/Link)
Internet Shortcuts API in ActiveX SDK has a function.
InetIsOffline
BOOL InetIsOffline (
DWORD dwFlags
);
Determines whether the system is connected to the Internet.
Returns TRUE if the local system in not currently connected to the Internet. Returns FALSE if the local system is connected to the Internet or if no attempt has yet been made to connect to the Internet.
dwFlags
Input flags for the function. This must be set to zero.
Internet Shortcuts API in ActiveX SDK has a function.
InetIsOffline
BOOL InetIsOffline (
DWORD dwFlags
);
Determines whether the system is connected to the Internet.
Returns TRUE if the local system in not currently connected to the Internet. Returns FALSE if the local system is connected to the Internet or if no attempt has yet been made to connect to the Internet.
dwFlags
Input flags for the function. This must be set to zero.
ASKER
Greate! My online detector function is working just fine now. But I'm courious about the InetIsOffline() function. When I add that function to the code I am getting the same error as before, so I presume that I need to add a Library file. But which? The error looks like this:
TestDlg.obj : error LNK2001: unresolved external symbol "int __cdecl InetIsOffline(unsigned long)" (?InetIsOffline@@YAHK@Z)
TestDlg.obj : error LNK2001: unresolved external symbol "int __cdecl InetIsOffline(unsigned long)" (?InetIsOffline@@YAHK@Z)