Back to the WFC main page

CRemoteAccessService : CObject

$Revision: 37 $

Description

This class makes RAS a little easier. From a programming perspective, RAS is like most Microsoft API's: almost useful. What's lacking from RAS is the ability to play with ports. I had to write software for a fault-tolerant mail postoffice and wrote a little program to page a system administrator when something went wrong. I had to dedicate one modem to this task because there's no way to tell RAS to release a port for other use. There's a RasPortxxx API that is not exposed so we lowly developer's can't use it. In short, it is impossible to write the RASPHONE application using the documented RAS API.

Constructors

CRemoteAccessService()
CRemoteAccessService( DWORD input_buffer_size )
CRemoteAccessService( DWORD input_buffer_size, output_buffer_size )
Constructs the object.

Methods

BOOL Close( LPCTSTR name_of_connection = NULL )
Same as HangUp() except it will not return until RAS really hangs up.
BOOL Dial( LPCTSTR who_to_call )
Dials a phone book entry. Makes a connection.
static BOOL EnableLogging( BOOL enable_logging, LPCTSTR machine_name = NULL )
This method allows you to enable logging of the connection. If set to TRUE, it will create a DEVICE.LOG file that holds the commands and responses during a RAS connection (when you dial).
HRASCONN GetConnection( LPCTSTR name_of_connection )
Gives you the HRASONN for the named connection.
BOOL GetConnections( CStringArray& connection_names )
Gives you a list of connection names. These are the names of the phone book entries that are currently connected. It is a list of the active RAS connections.
BOOL GetConnectionStatus( void )
Returns TRUE is you're connected.
LONG GetErrorCode( void ) const
Returns the error code should any function return FALSE.
BOOL GetErrorString( CString& error_string )
Same as GetErrorCode() but it gives you a human readable string instead of a number.
BOOL GetKeepConnectionsAfterLogoff( LPCTSTR machine_name = NULL )
Tells you if your RAS connections will be dropped (disconnected) when the user logs off. If is not NULL,
void GetName( CString& name )
Gives you the name of the connection that was successfully Open()'d or Dial()'d.
BOOL GetPhoneBookEntries( CStringArray& phone_book_entries )
Gives you back a list of phone book entry names. You can use these names to pass to Dial().
BOOL GetProtocolInformation( CRemoteAccessServiceAuthenticationMessageBlock& data_to_get )
BOOL GetProtocolInformation( CRemoteAccessServiceNetBEUIFramer& data_to_get )
BOOL GetProtocolInformation( CRemoteAccessServiceInternetworkPacketExchange& data_to_get )
BOOL GetProtocolInformation( CRemoteAccessServiceInternetProtocol& data_to_get )
Gives you back information about the networking protocol used on the active connection.
BOOL HangUp( LPCTSTR name_of_connection = NULL )
Tells RAS to terminate the connection. NOTE! When this function returns, THE CONNECTION HAS NOT BEEN TERMINATED!! If you immediately exit from your thread/process after calling HangUp(), the connection will be left in a random state. It is much safer to use Close() instead.
BOOL IsConnected( void )
Returns TRUE if you're connected.
BOOL Open( LPCTSTR who_to_call )
Same as Dial but lets you treat RAS like most other object in WFC.
BOOL SetAutomaticallyClose( BOOL automatically_close )
When this property is TRUE, the destructor will terminate the connection if there is one.
LPVOID SetConnectionCallback( LPVOID RasDialFunc1_function_pointer )
Lets you pass a pointer to a function so you can monitor the progress of RAS.
HWND SetConnectionCallbackWindow( HWND window_handle )
Lets you pass a window handle that will receive WM_RASDIALEVENT messages so you can monitor the progress of RAS.
DWORD SetDialOptions( DWORD dial_options )
Let's you set the dialing options.
BOOL SetKeepConnectionsAfterLogoff( BOOL keep_connections = TRUE, LPCTSTR machine_name )
Lets you tell NT whether or not it should drop all RAS connections when the current user logs off.

Example

#include <wfc.h>
#pragma hdrstop

void test_CRAS( void )
{
   WFCTRACEINIT( TEXT( "test_CRAS()" ) );

   CRemoteAccessService ras;

   CStringArray strings;

   ras.SetDialOptions( CRemoteAccessService::dialAcceptPausedStates );

   if ( ras.GetPhoneBookEntries( strings ) != FALSE )
   {
      DWORD index = 0;
      DWORD number_of_entries = strings.GetSize();

      TRACE( TEXT( "Phone Book Entries:\n" ) );

      while( index < number_of_entries )
      {
         TRACE1( TEXT( "\"%s\"\n" ), (LPCTSTR) strings[ index ] );
         index++;
      }
   }

   strings.RemoveAll();

   if ( ras.GetConnections( strings ) != FALSE )
   {
      DWORD index = 0;
      DWORD number_of_entries = strings.GetSize();

      TRACE( TEXT( "\nCurrent Connections:\n" ) );

      while( index < number_of_entries )
      {
         TRACE1( TEXT( "\"%s\"\n" ), (LPCTSTR) strings[ index ] );
         index++;
      }
   }

   if ( ras.Open( TEXT( "EROLS" ) ) == FALSE )
   {
      CString error_string;
      ras.GetErrorString( error_string );
      TRACE1( TEXT( "Ras Open failed with \"%s\"!\n" ), (LPCTSTR) error_string );
   }
   else
   {
      TRACE( TEXT( "RAS Open!\n" ) );
   }

   strings.RemoveAll();

   if ( ras.GetConnections( strings ) != FALSE )
   {
      DWORD index = 0;
      DWORD number_of_entries = strings.GetSize();

      TRACE( TEXT( "\nCurrent Connections:\n" ) );

      while( index < number_of_entries )
      {
         TRACE1( TEXT( "\"%s\"\n" ), (LPCTSTR) strings[ index ] );
         index++;
      }
   }

   if ( ras.HangUp( TEXT( "EROLS" ) ) != FALSE )
   {
      TRACE( TEXT( "Hangup OK\n" ) );
   }
}

API's Used


Copyright, 2000, Samuel R. Blackburn
$Workfile: cras.cpp $
$Modtime: 1/17/00 9:12a $