Solved

Check if online

Posted on 1997-12-07
7
232 Views
Last Modified: 2008-02-01
Is there some easy way to check if you are online from a program made in Visual C++?
0
Comment
Question by:od0
  • 3
  • 3
7 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1175064
You can use the Remote Access Service (RAS) function RasEnumConnections to check if there are any Dial-Up Networking connections.
0
 

Author Comment

by:od0
ID: 1175065
Can you please specify how to use the RasEnumConnections command?
I can't make it work...
0
 
LVL 23

Expert Comment

by:chensu
ID: 1175066
// 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(lpConn, &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;
}

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:od0
ID: 1175067
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?
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 total points
ID: 1175068
You need to link with RASAPI32.LIB.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1175069
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.
0
 

Author Comment

by:od0
ID: 1175070
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)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now