Solved

Anyone have a C++ example of RasEnumConnections implementation?

Posted on 1998-09-29
4
1,249 Views
Last Modified: 2012-05-04
Anyone have a C++ example of RasEnumConnections implementation?  Also, how would you iterate through the returned connections to see if the connection you are trying to make is already connected?
0
Comment
Question by:afalvey
  • 2
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 1174037
//
// Check the state of any RAS connection
//
char *CWindow::CheckRAS(DWORD *state, char *hostip)
{

      RASCONN *ras_buf;
      RASPPPIP *prasip;
      DWORD sz_ras_buf, numconn, errcd, szrasip;
      HRASCONN hrc;
      static char rasname[256];

      // Allocate space for RASCONN buffers
      ras_buf = (RASCONN *)malloc(32 * sizeof(RASCONN));
      sz_ras_buf = 32 * sizeof(RASCONN);

      ras_buf->dwSize = sizeof(RASCONN);

      if((errcd = RasEnumConnections(ras_buf, &sz_ras_buf, &numconn)) != 0){
          *state = RAS_ERROR;
          free(ras_buf);
            return NULL;
      }

      if(numconn > 0){
            hrc = ras_buf->hrasconn;

            prasip = (RASPPPIP *)malloc(sizeof(RASPPPIP));
            szrasip = sizeof(RASPPPIP);
            prasip->dwSize = szrasip;

            errcd = RasGetProjectionInfo(hrc, RASP_PppIp, prasip, &szrasip);
            switch(errcd){

                  default:
                      *state = RAS_ERROR;
                      free(ras_buf);
                      return NULL;
                  case 0:
                        *state = RAS_CONN;
                        strcpy(rasname, ras_buf->szEntryName);
                        strcpy(hostip, prasip->szIpAddress);
                        if(strlen(rasname) > 0){
                            free(ras_buf);
                            return(rasname);
                      }
                      else{
                          *state = RAS_ERROR;
                          free(ras_buf);
                          return NULL;
                      }

                  case 731:
                      *state = RAS_DIAL;
                      strcpy(rasname, ras_buf->szEntryName);
                        if(strlen(rasname) > 0){
                            free(ras_buf);
                            return(rasname);
                      }
                      else{
                          *state = RAS_ERROR;
                          free(ras_buf);
                          return NULL;
                      }
            }
      }
      else{
          *state = RAS_NOCONN;
          free(ras_buf);
          return NULL;
      }
}
0
 

Expert Comment

by:ext3awf
ID: 1174038
Do you have to include any headers other than:
ras.h and raserror.h?
0
 

Expert Comment

by:ext3awf
ID: 1174039
I've been trying this but I always get the default: state even when I'm connected.  Any suggestions?

LPRASENTRYNAME RasEntry;                        
                        DWORD Buffer;
                        DWORD Entry;
                        DWORD Retrn;
                        DWORD  Index;
                        
                        Buffer = sizeof(RASENTRYNAME);
                        
                        //RasEntry->dwSize = sizeof(RASENTRYNAME);

                        Retrn = RasENUMENTRIES( NULL, NULL, RasEntry, &Buffer, &Entry );                        
                        
                        //the buffer is too small
                        if (Retrn == 603)
                        {
                              RasEntry->dwSize = sizeof(RASENTRYNAME);
                              Retrn = RasENUMENTRIES( NULL, NULL, RasEntry, &Buffer, &Entry );                        
                        }

                        if ( Retrn != 0 )  //error
                        {
                              m_IAmConnected = FALSE;                                    
                              FireErrorLaunchingDialUpAccount(m_StringResource->LoadString(ERR_COMM_ERROR_LAUNCHING_DIAL_UP_ACCOUNT));                                                      
                        }

                        if ( Retrn == 0 )  // no errors
                        {
                              for ( Index = 0; Index < Entry; Index++ )
                              {                              
                                    if (rdParams.szEntryName == RasEntry[Index].szEntryName);
                                    {
                                          //get connection status for this entry
                                          RASCONNSTATUS ConnectionStatus;                        
                        
                                          ConnectionStatus.dwSize = sizeof(RASCONNSTATUS);

                                          RasCONNECTSTATUS(m_hRasConn,  // handle to RAS connection of interest
                                                                  &ConnectionStatus);      // buffer to receive status data
                                                                                                
                                          switch( ConnectionStatus.rasconnstate )
                                          {                                                
                                                case RASCS_Connected:
                                                      m_IAmConnected = TRUE;          
                                                
                                                //dial-up failed
                                                case RASCS_Disconnected:
                                                m_IAmConnected = FALSE;                                                      
                                                
                                                
                                                default:
                                                m_IAmConnected = FALSE;                                                                                                                              
                                          }                  
                                          
                                    }                              
                              }
                        }
0
 
LVL 32

Expert Comment

by:jhance
ID: 1174040
You have no "break;" in your "case:" statements!!!!!

switch( ConnectionStatus.rasconnstate )
{
case RASCS_Connected:
m_IAmConnected = TRUE;            
break;

//dial-up failed
case RASCS_Disconnected:
m_IAmConnected = FALSE;
break;

default:
m_IAmConnected = FALSE;
}
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

770 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