Solved

RAS function

Posted on 2000-05-07
8
440 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

911 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

23 Experts available now in Live!

Get 1:1 Help Now