Solved

RAS function

Posted on 2000-05-07
8
446 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

860 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