Solved

RAS function

Posted on 2000-05-07
8
436 Views
Last Modified: 2008-02-20
I need the sourcecode for a function which returns the number of RAS connections currently connected.

It needs to be simple (I'm not the best at Visual C). It would be really helpful if the full source of a console app could be posted.

I've looked at previous questions here, looked at RASBerry, and looked in news groups and have not yet found something simple enough for me to understand.

Thanks.
0
Comment
Question by:nedrub
  • 4
  • 4
8 Comments
 
LVL 3

Accepted Solution

by:
mitrakis earned 200 total points
ID: 2785644
Here's an abstract from my own project.
The intereesting part is RasEnumConnection().
More info on it can be found in MSDN library.

BOOL CRasClient::GetRasConnection(CString strEntryName, HRASCONN & hrasConn)
{
      BOOL bFind = FALSE;
      CString strEntry;
      DWORD dwSizeBuf = 0;
      DWORD dwConnections = 0;
      RASCONN rasConn;
      rasConn.dwSize = sizeof(rasConn);
      DWORD dw = RasEnumConnections(&rasConn, &dwSizeBuf, &dwConnections);
      if(dwConnections <= 0)
            return FALSE;
      RASCONN *lpRasConn = new RASCONN[dwConnections];
      lpRasConn->dwSize = sizeof(*lpRasConn);
      RasEnumConnections(lpRasConn, &dwSizeBuf, &dwConnections);
      for(DWORD i = 0; i < dwConnections; i++)
      {
            strEntry = lpRasConn[i].szEntryName;
            if(strEntry.CompareNoCase(strEntryName) == 0)
            {
                  hrasConn = lpRasConn[i].hrasconn;
                  bFind = TRUE;
            }
      }
      delete []lpRasConn;
      if(bFind)
            return TRUE;
      else
            return FALSE;
}


Let me know if you need further info.

Best regards
-Stavi-
0
 

Author Comment

by:nedrub
ID: 2785689
Thanks for the very fast response (best I've experienced yet!).

I'm having a little trouble - probably missing some includes higher up.

First I couldn't get the code to compile so I changed your last four lines to just:

     return bFind;

(why this compiled when yours didn't is beyond me).

But now I'm getting 30 errors - mainly "undeclared identifier" or similar.

My includes are windows.h and ras.h - what else do I need, and how exactly do I call your function?

Sorry I'm so slow - I can't believe that (many years ago) I actually got a High Distinction in network C++ programing at university!

Nedrub.
0
 
LVL 3

Expert Comment

by:mitrakis
ID: 2785805
Sorry, as I said this is just an excerpt from my own project.
You'll need to include ***"ras.h"***, that's all.

Instead of cut'n pasting the above code, use this one to avoid too many errors ;)

BOOL GetRasConnection()
{
      DWORD dwSizeBuf = 0;
      DWORD dwConnections = 0;
      RASCONN rasConn;
      rasConn.dwSize = sizeof(rasConn);
      DWORD dw = RasEnumConnections(&rasConn, &dwSizeBuf, &dwConnections);
      if(dwConnections <= 0)
            return FALSE; //no connections detected

      return TRUE;  //at least one connection detected
}
0
 

Author Comment

by:nedrub
ID: 2785900
Sorry Stavi,

I'm still not quite there. It's compiling fine, but when I try to build I get the following output . . .

------------------------------------

Compiling...
RAS.cpp
Linking...
RAS.obj : error LNK2001: unresolved external symbol _RasEnumConnectionsA@12
Debug/test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

test.exe - 2 error(s), 0 warning(s)

------------------------------------

I'm probably missing something really obvious.

I've included my full source below...

------------------------------------

#include <windows.h>
#include "ras.h"

BOOL GetRasConnection()
{
DWORD dwSizeBuf = 0;
DWORD dwConnections = 0;
RASCONN rasConn;
rasConn.dwSize = sizeof(rasConn);
DWORD dw = RasEnumConnections(&rasConn, &dwSizeBuf, &dwConnections);
if(dwConnections <= 0)
return FALSE; //no connections detected

return TRUE;  //at least one connection detected
}

void main()
{
  BOOL b;
  b=GetRasConnection();
}
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:mitrakis
ID: 2786492
Just a little thing I forgot to mention (shame on me...)

You have to add rasapi32.lib in your compiler/lib settings.
If you need to know where to set this up leave me a note.

Best regards
-Stavi-

P.S.:
Ensure that "BOOL GetRasConnection();" is defined in your header, too...
0
 

Author Comment

by:nedrub
ID: 2786682
Adjusted points from 100 to 200
0
 

Author Comment

by:nedrub
ID: 2786684
Thanks guys, I've increased points due to the "double post issue" and the fact that I needed help with extra, basic issues.
0
 
LVL 3

Expert Comment

by:mitrakis
ID: 2787243
Thank you very much...and good luck with your project.

Best regards
-Stavi-
0

Featured Post

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

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

746 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

12 Experts available now in Live!

Get 1:1 Help Now