Compartir a través de


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;
}

See Also

Phone-Book Operation

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.