2009. 5. 7. 17:33

Phonebook Operation


Phone-Book Operation

Entries in the Remote Access Service phone book contain the data necessary to establish a RAS connection. Unlike Windows-based desktop operating systems, which keep phone-book entries in a file, Windows CE stores these entries in the registry.

To make a connection without using a phone-book entry, RasDial can specify an empty string for the szEntryName member of the RASDIALPARAMS structure. The szPhoneNumber member must contain the phone number to dial.

RAS phone-book data includes:

·                 The phone number to dial, including country/region code and area code.

·                 The IP addresses to use while the connection is active.

·                 The network protocols.

·                 The type of device used to make the connection.

Windows CE supports a limited set of Window-based desktop functions for working with phone-book entries. The application can use the RasGetEntryProperties or RasSetEntryProperties function to create or edit a phone-book entry. The application can use the RasGetEntryDialParams and RasSetEntryDialParams functions to set or retrieve the connection parameters for a phone-book entry. The RasEnumEntries function lists all the phone-book entry names using the RASENTRY structure.

Data for the RAS phone book is stored in the registry under the HKEY_CURRENT_USER\Comm\RasBook key. See RAS Registry Settings for details.

Creating or Changing a Phone-Book Entry

You can use use the RasSetEntryProperties function to create or change phone-book entries.

To create or change registry phone-book entries

1.               Call RasValidateEntryName to be sure that the name does not exist.

2.               If you are editing an existing entry, call RasGetEntryProperties to retrieve the existing configuration.

3.               Call RasSetEntryProperties to set the new configuration. The following glist shows how the parameters should be set:

·                         The lpszName parameter should point to the null-terminated string containing the entry name in the lpszEntry parameter. If the existing name matches an existing entry, RasSetEntryProperties modifies the entry properties. If the entry does not exist, the function creates a new entry.

·                         The lpszEntry parameter should point to a RASENTRY structure, which should be filled with data for the connection, including the telephone number, device type, and name.

·                         The lpbDeviceInfo and dwDeviceInfoSize parameters can be used to set Telephony API (TAPI) device configuration data.

Creating a Phone-Book Entry Example

The following code example shows how to create a phone-book entry.

int CreateRasEntry (LPTSTR lpszName)
{
  DWORD dwSize,
        dwError;
  TCHAR szError[100];
  RASENTRY RasEntry;
  RASDIALPARAMS  RasDialParams;
 
  // Validate the format of a connection entry name.
  if (dwError = RasValidateEntryName (NULL, lpszName))
  {
    wsprintf (szError, TEXT("Unable to validate entry name.")
              TEXT(" Error %ld"), dwError);  
 
    return FALSE;
  }
 
  // Initialize the RASENTRY structure.
  memset (&RasEntry, 0, sizeof (RASENTRY));
 
  dwSize = sizeof (RASENTRY);
  RasEntry.dwSize = dwSize;
 
  // Retrieve the entry properties.
  if (dwError = RasGetEntryProperties (NULL, TEXT(""),      
                      (LPBYTE)&RasEntry, &dwSize, NULL, NULL))  
  {
    wsprintf (szError, TEXT("Unable to read default entry properties.")
              TEXT(" Error %ld"), dwError);
    return FALSE;
  }
 
  // Insert code here to fill the RASENTRY structure.
  // ...
  
  // Create a new phone-book entry.
  if (dwError = RasSetEntryProperties (NULL, lpszName, 
                      (LPBYTE)&RasEntry, sizeof (RASENTRY), NULL, 0))
  {
    wsprintf (szError, TEXT("Unable to create the phonebook entry.")
              TEXT(" Error %ld"), dwError);
    return FALSE;
  }
 
  // Initialize the RASDIALPARAMS structure.
  memset (&RasDialParams, 0, sizeof (RASDIALPARAMS));
  RasDialParams.dwSize = sizeof (RASDIALPARAMS);
  _tcscpy (RasDialParams.szEntryName, lpszName);
  
  // Insert code here to fill up the RASDIALPARAMS structure.
  // ...
 
  // Change the connection data.
  if (dwError = RasSetEntryDialParams (NULL, &RasDialParams, FALSE))
  {
    wsprintf (szError, TEXT("Unable to set the connection information.")
              TEXT(" Error %ld"), dwError);
    return FALSE;
  }
 
  return TRUE;
}

Changing an Existing Phone-Book Entry

The RasRenameEntry function renames a phone-book entry in the registry, while the RasDeleteEntry function deletes an entry. To verify if the string is in the correct format, the application can use the RasValidateEntryName function.

To change a registry phone-book entry

1.               Call RasValidateEntryName to verify the new name.

2.               Call the RasRenameEntry function to change the name.

The return value is zero if successful, and a RAS error value is returned if it is not successful.

Changing a Phone-Book Entry Example

The following code example shows how to change an existing phone-book entry.

BOOL RenameRasEntry (LPTSTR lpszOldName, LPTSTR lpszNewName)
 
{
  DWORD dwError;            // Return code from functions 
  TCHAR szError[120];       // Buffer for error message 
 
  if (dwError = RasValidateEntryName (NULL, lpszNewName))
  {
    wsprintf (szError, TEXT("Entry name validation failed: %ld"), 
              dwError);
    return FALSE;
  }
 
  if (dwError = RasRenameEntry (NULL, lpszOldName, lpszNewName))
  {
    wsprintf (szError, TEXT("Unable to rename entry: %ld"), dwError);
    return FALSE;
  }
 
  return TRUE;
}

Enumerating Phone-Book Entries

The RasEnumEntries function is used to enumerate a list of phone-book entries. Using this list, a user can select a RAS connection.

To enumerate phone-book entries

1.               Allocate an array for the RASENTRYNAME structure.

2.               Call RasEnumEntries to list the names in the phone book.

3.               Display the list for a user.

Enumerating Phone-Book Entry Example

The following code example shows how to dial and connect to a phone-book entry in the registry.

BOOL GetPhonebookEntries (HWND hDlgWnd)
{
  int index;
  DWORD dwSize, 
        dwEntries;
  HWND hWndListBox;
 
  // Allocate an array of RASENTRYNAME structures. Assume 
  // no more than 20 entries to be configured on the 
  // Windows CE-based device.
 
  if (!(lpRasEntryName = new RASENTRYNAME [20]))
  {
    MessageBox (hDlgWnd, TEXT("Not enough memory"), szTitle, MB_OK);
    return FALSE;
  }
 
  // Initialize the dwSize member of the first RASENTRYNAME structure
  // in the array to the size of the structure to identify 
  // the version of the structure being passed.
  lpRasEntryName[0].dwSize = sizeof (RASENTRYNAME);
 
  // Size of the array, in bytes
  dwSize = sizeof (RASENTRYNAME) * 20;
 
  // List all entry names in a remote access Phone book.
  if ((RasEnumEntries (
          NULL,               // Reserved, must be NULL
          NULL,               // Phone book is stored in the Windows CE
                              // registry.
          lpRasEntryName,     // Pointer to structure to receive entries
          &dwSize,            // Size of lpRasEntryName, in bytes
          &dwEntries)) != 0)  // Number of entries placed in array
  {
    MessageBox (hDlgWnd, TEXT("Could not obtain RAS entries"), szTitle,
                MB_OK);
    return FALSE;
  }
 
  // Get the HWND of the list box control.
  hWndListBox = GetDlgItem (hDlgWnd, IDC_RASNAMES);
 
  // Remove all items from a list box.
  SendMessage (hWndListBox, LB_RESETCONTENT, 0, 0);
 
  // Add the names of each RAS connection to the list box.
  for (index = 0; index < (int)dwEntries; ++index)
  {
    SendMessage (hWndListBox, LB_INSERTSTRING, index, 
                 (LPARAM)lpRasEntryName[index].szEntryName);
  }
 
  return TRUE;
}

Copying a Phone-Book Entry

An application can use the RasGetEntryProperties or RasSetEntryProperties function to copy the configuration data to another entry. The lpszEntryName parameter can be used to change the entry.

To copy a phone-book entry to the dialing list

1.               Call RasGetEntryProperties to get current phone-book properties.

2.               Call RasSetEntryProperties to set new phone-book properties.

3.               Call RasGetEntryDialParams to retrieve current user data.

4.               Call RasSetEntryDialParams to set user password data.

The return value is TRUE if successful and FALSE if not.

Deleting a Phone-Book Entry

To delete a phone-book entry the application can use the RasDeleteEntry function.

To delete a phone-book entry from the dialing list

·                 Call RasDeleteEntry using the lpszName parameter to supply the entry to be deleted.

The return value is TRUE if successful and FALSE if not.

Deleting a Phone-Book Entry Example

The following code example shows how to delete a RAS phone-book entry from the dialing list.

BOOL DeleteRasEntry (LPTSTR lpszName)
{
  DWORD dwError;            // Return code from RasDeleteEntry
  TCHAR szError[100];       // Buffer for error message 
 
  if (dwError = RasDeleteEntry (NULL, lpszName))
  {
    wsprintf (szError, TEXT("Unable to delete entry: %ld"), dwError);
    return FALSE;
  }
 
  return TRUE;
}

[출처] PhoneBook Entry|작성자 새벽