Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Anyone have a C++ example of RasEnumConnections implementation?

Posted on 1998-09-29
4
Medium Priority
?
1,315 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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.

916 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