[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

RAS function

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
nedrub
Asked:
nedrub
  • 4
  • 4
1 Solution
 
mitrakisCommented:
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
 
nedrubAuthor Commented:
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
 
mitrakisCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
nedrubAuthor Commented:
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
 
mitrakisCommented:
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
 
nedrubAuthor Commented:
Adjusted points from 100 to 200
0
 
nedrubAuthor Commented:
Thanks guys, I've increased points due to the "double post issue" and the fact that I needed help with extra, basic issues.
0
 
mitrakisCommented:
Thank you very much...and good luck with your project.

Best regards
-Stavi-
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now