CUT_RAS Overview

Dundas

CUT_RAS Overview

Copyright © Dundas Software Ltd. 1996-1999, All Rights Reserved

CUT_RAS Class Members

Dependencies and Related Files


The RAS Dialup class (CUT_RAS) is part of the Ultimate TCP/IP client and enterprise editions and provides easy to use modem dialing capabilities. This class allows you to create and modify dial-up entries, dial and hang up connections and more. CUT_RAS works within MFC, ATL and straight SDK projects.

CUT_RAS works with the main system phonebook.

To utilize your own errorcodes you can use UTExtErr.h.

Sample Code:

The following code demonstrates how to set up a dialog box in order to dial the first entry in a system phone book, and a user defined WM (window message ) is created to inform us of the dialup progress.
 

NOTE: for this demo to work you must have Dial Up Networking installed. Please refer to CUT_RAS Dependencies and Related Files for a listing of dependency files.

To run this sample code follow the steps below:

  1. Open a new win32 project. 

  2. Insert a new dialog (named IDD_DIALOG1).

  3. Rename the OK  button of the dialog to IDC_DIAL.

  4. Add an edit control named IDC_EDIT1.

  5. Add a new header file "stdafx.h" that contains the following four lines of code:

    #ifndef __UT_RAS12345_STDAFX
    #define
      __UT_RAS12345_STDAFX
    #include
    <windows.h>
    #endif
    // __UT_RAS12345_STDAFX

  6. Locate and add ut_RAS.h & ut_RAS.cpp to the project.

  7. Create a new c++ source file (lets call it main.cpp).

  8. Copy and past the code shown below 

  9. Run the program.

For an MFC sample please see the project included with the install program for this class.

 

#include "stdafx.h"  // the stdafx file

 

//The header file of CUT_RAS class

#include "ut_ras.h"

 

//resource header for a dialog (IDD_DIALOG1) which contains a cancel button (IDCANCEL),

// a dial button and a read only edit box (IDC_EDIT1)

#include "resource.h"

 

// User defined window message that will be sent back to us by the

// CUT_RAS class to inform us of the dial up progress

#define WM_CUT_RAS_DIALSTATUS WM_USER+1

 

// Dialog proc Prototype

BOOL CALLBACK DialupDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);

 

// Window Main function

int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE ,LPSTR ,int)

{

 

//create modal dialog box

DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL, (DLGPROC )DialupDlgProc);

return 0;

}

 

// Dialog proc

BOOL CALLBACK DialupDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)

{

 

// a static instance of the CUT_RAS object

static CUT_RAS ras;

 

// Pool the window messages

switch (message) {

case WM_INITDIALOG:

{

 

// upon initializing this dialog lets instruct the CUT_RAS object to send this dialog

// our user defined message to report the dialup status.

ras.SetDialStatusCallback (hwndDlg,WM_CUT_RAS_DIALSTATUS);

return 1;

}

 

// handle user inputs

case WM_COMMAND:

switch (LOWORD(wParam))

{

// user pressed the cancel button

case IDCANCEL:

{

// abort any bending dial attempt if any

ras.CancelDial ();

 

// Hang up the current connection

ras.HangUp ();

 

// Exit closing this dialog

EndDialog(hwndDlg, IDOK);

break;

}

 

// user pressed the dial button

case IDC_DIAL:

{

 

// create a phone entry name place holder

LPRASENTRYNAME ren = new RASENTRYNAME [sizeof(RASENTRYNAME)+1];

 

// clear any data in the new allocated memory

memset(ren,0,sizeof(RASENTRYNAME));

 

// initialize the RAS dll and enumerate the available entries

ras.EnumEntries();

 

// get the first entry

ras.GetEntry ( ren,0);

 

// dial the first entry in the phonebook

ras.Dial(ren->szEntryName);

 

// reclaim the allocated memory

delete [] ren;

break;

}

}

break;

 

// if this incoming message is the same as the one we specified as the dial status notification

// then get the string from the Lower word of the message parameter

// and display it in the status edit box.

case WM_CUT_RAS_DIALSTATUS :

{

SetDlgItemText(hwndDlg, IDC_EDIT1,(LPCSTR)(LPARAM)lParam);

return 1;

}

 

// the window is closing

case WM_CLOSE:{

 

// abort any pending dial attempts (if any exist)

ras.CancelDial ();

 

// Hang up the current connection

ras.HangUp ();

EndDialog(hwndDlg, IDOK);

break;

}

}

return 0;

}