Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RAS function

Posted on 2000-05-07
8
Medium Priority
?
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 3

Accepted Solution

by:
mitrakis earned 800 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

636 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