Chris De Herrera's Windows CE Website

About
Discuss.Pocket PC FAQ Forum
Add Pocket PC FAQ to your Favorites
RSS    RSS Feeds
Wiki    Lost?
Subscribe    Print

Developer

Miscellaneous
Table of Contents
Mobile Format

Pocket PC Blast


 
Pocket PC Magazine Best Site

Website Awards
Website Updates

By Chris De Herrera 
Copyright 1998-2007
 All Rights Reserved
A member of the Talksites Family of Websites

Windows and Windows CE are trademarks of Microsoft
Corporation
and are used
under license from owner.
CEWindows.NET is not
associated with Microsoft 
Corporation.

All Trademarks are owned
by their respective companies.

RAS
By Terence "Dr. CE" Goggin
Copyright 2000, 2001 Terence Goggin
 Version 1.00  Revised 4/20/01

Shop unique and cheap iPhone cases on DHgate.com

Topics

1. How do I establish a RAS Dial-up connection?
2. How do I hang up a RAS connection?
3. How do I handle RAS notifications?



1. How do I establish a RAS Dial-up connection?
The code below shows how to use RasDial() to establish
a RAS connection; however, it's worth noting that it uses
a pre-existing RAS entry to do so.

While it's possible to enter the various parameters via
code, using an existing dial up entry is considerably easier.

#define ENTRY                       TEXT("testconn") /* name of dial up conn entry */
#define USERNAME       TEXT("testpda") /* User id */
#define PASSWORD       TEXT("testpda1")   /* pass */

//hNotify is the window to receive RAS status notification msgs
BOOL DialUp(HWND hNotify)
{
    /* Initialize */
    // Fill out rasDialParams from phone book entry

  BOOL fPassword = FALSE; //TRUE if password has been retrived from phone book entry
  BOOL fHavePhoneNumber = TRUE; // phone book entry has a phone number
  lstrcpy(g_DialInfo.rasDialParams.szEntryName, ENTRY);
  g_DialInfo.rasDialParams.dwSize = sizeof(RASDIALPARAMS);
  RasGetEntryDialParams(NULL, &(g_DialInfo.rasDialParams), &fPassword);
      /* call API */
   
      DWORD dwRet = RasDial(NULL, NULL, &(g_DialInfo.rasDialParams), 0xFFFFFFFF, hNotify, & (g_DialInfo.hRasConn));
     
    /* check the result */
                                                     
      if (dwRet == 0)
      {
              return TRUE;
      }
      else
      {
              return FALSE;
      }

}



2. How do I hang up a RAS connection?
I think this code speaks for itself... can be used in
conjunction with the code from the previous question....


BOOL HangUp()
{

      if(g_DialInfo.hRasConn!=NULL)
      {
              return RasHangUp(g_DialInfo.hRasConn);
      }
      return TRUE; //already hung up

}



3. How do I handle RAS notifications?
Somewhere inside your WndProc(), add a message handler
similar to the one shown here...

              case WM_RASDIALEVENT:
                      WCHAR szMessage[256];
             
                      LoadString(hInst, GetRasConnState( (RASCONNSTATE) wParam ), szMessage, 64 );

                      if ((DWORD)lParam)
                      {
                              wsprintf(szMessage, L"Unable to complete connection. Error %d", GetLastError());
                              MessageBox((HWND)hDlg, szMessage, L"Error", MB_ICONSTOP | MB_OK);
                              //ExitThread(0);
                              return 0;
                      }
                      switch( (RASCONNSTATE) wParam )
                      {
                              case RASCS_OpenPort:
                                      break;
                              case RASCS_PortOpened:
                                      break;
                              case RASCS_ConnectDevice:
                                      break;
                              case RASCS_DeviceConnected:
                                      break;
                              case RASCS_AllDevicesConnected:
                                      break;
                              case RASCS_Authenticate:
                                      break;
                              case RASCS_AuthNotify:
                                      break;
                              case RASCS_AuthRetry:
                                      break;
                              case RASCS_AuthCallback:
                                      break;
                              case RASCS_AuthChangePassword:
                                      break;
                              case RASCS_AuthProject:
                                      break;
                              case RASCS_AuthLinkSpeed:
                                      break;
                              case RASCS_AuthAck:
                                      break;
                              case RASCS_ReAuthenticate:
                                      break;
                              case RASCS_Authenticated:
                                      break;
                              case RASCS_PrepareForCallback:
                                      break;
                              case RASCS_WaitForModemReset:
                                      break;
                              case RASCS_WaitForCallback:
                                      break;
                              case RASCS_Interactive:
                                      break;
                              case RASCS_RetryAuthentication:
                                      break;
                              case RASCS_CallbackSetByCaller:
                                      break;
                              case RASCS_PasswordExpired:
                                      break;    
                              case RASCS_Disconnected:
                                      //hang up
                                      break;                                            
                              case RASCS_Connected:
                                      //you're in!
                                      break;
                              default:
                                      break;

                      }
                      break;



Terence Goggin's DoctorCE.com site - Custom Windows CE development/consulting services.

Return to Chris De Herrera's Windows CE Website


Questions? Comments? Suggestions? Email Terence "Dr. CE" Goggin.