Solved

Anyone have a C++ example of RasEnumConnections implementation?

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

728 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