Currently viewing: GipsySoft » Front Page» Articles

CDynamicRas

Small class that wraps the nasty LoadLibrary/GetProcAddress calls when you want to dynamically bind to the RAS library

Note that I have not added all of the RAS functions because I have not used them and therefore have not been in a position to test them, what is there has been used and tested. It should be easy to add extra functions as they are requried. If you do add any new functions then please let me have the modified code so that otehr may benefit from it.

Example

#include <CDynamicRas.h>

...

static bool IsInternetOffline()
//
//  Determine whether we are currently offline
{
  CDynamicRAS ras;
  bool fRet = false;
  RASCONN rascon[20];
  DWORD dSize = 20, dNumber;
  rascon[0].dwSize = sizeof(RASCONN);
  dSize = sizeof( rascon );
  if( ras.IsRASLoaded()
    && !ras.RasEnumConnections( rascon, &dSize, &dNumber )
    && dNumber == 0)
  {
    fRet = true;
  }

  return fRet;
}


bool DisconnectRas()
//
//  Disconnect all RAS connections
{
  bool bOk = false;
  RASCONN rascon[20];
  DWORD dSize,dNumber,dCount;
  rascon[0].dwSize = sizeof(RASCONN);
  dSize = sizeof( rascon );   // Get active RAS - Connection
  CDynamicRAS ras;
  if( ras.IsRASLoaded() )
  {
    if( ras.RasEnumConnections( rascon, &dSize, &dNumber ) == 0 )
    {
      bOk = true;
      for( dCount = 0; dCount < dNumber; dCount++ )
      {
        // Hang up that connection
        if( ras.RasHangUp( rascon[dCount].hrasconn) != 0 )
        {
          bOk = false;
          break;
        }
        else
        {
          //  Wait for the connection to die.
          RASCONNSTATUS r;
          r.dwSize = sizeof(RASCONNSTATUS);
          while( ras.RasGetConnectStatus( rascon[dCount].hrasconn, &r ) != ERROR_INVALID_HANDLE )
          {
            Sleep( 0 );
          }
        }

      }
    }
  }
  else
  {
    bOk = true;
  }
  return bOk;
}


 

Click to download the ZIP file

See also none