Solved

Anyone have a C++ example of RasEnumConnections implementation?

Posted on 1998-09-29
4
1,240 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

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

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 …
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

867 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

18 Experts available now in Live!

Get 1:1 Help Now