Link to home
Start Free TrialLog in
Avatar of afalvey
afalvey

asked on

Anyone have a C++ example of RasEnumConnections implementation?

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?
ASKER CERTIFIED SOLUTION
Avatar of jhance
jhance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ext3awf
ext3awf

Do you have to include any headers other than:
ras.h and raserror.h?
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;                                                                                                                              
                                          }                  
                                          
                                    }                              
                              }
                        }
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;
}