RasDialDlgA function

The RasDialDlg function establishes a RAS connection using a specified phone-book entry and the credentials of the logged-on user. The function displays a stream of dialog boxes that indicate the state of the connection operation.


BOOL RasDialDlgA(
  LPSTR        lpszPhonebook,
  LPSTR        lpszEntry,
  LPSTR        lpszPhoneNumber,



Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file. If this parameter is NULL, the function uses the current default phone-book file. The default phone-book file is the one selected by the user in the User Preferences property sheet of the Dial-Up Networking dialog box.


Pointer to a null-terminated string that specifies the name of the phone-book entry to dial.


Pointer to a null-terminated string that specifies a phone number that overrides the numbers stored in the phone-book entry. If this parameter is NULL, RasDialDlg uses the numbers in the phone-book entry.


Pointer to a RASDIALDLG structure that specifies additional input and output parameters. The dwSize member of this structure must specify sizeof(RASDIALDLG). If an error occurs, the dwError member returns an error code; otherwise, it returns zero.

Return Value

If the function establishes a RAS connection, the return value is TRUE. Otherwise, the function should return FALSE.

If an error occurs, RasDialDlg should set the dwError member of the RASDIALDLG structure to a value from Routing and Remote Access Error Codes or Winerror.h.


The RasDialDlg function displays a series of dialog boxes that are similar to the dialog boxes the main Dial-Up Networking dialog box displays when the user selects the Dial button. Use the RasDialDlg function to display a standard user interface for a connection operation without presenting the main phone-book dialog box. For example, the RAS AutoDial service uses this function to establish a connection using the phone-book entry associated with a remote address.

The RasDialDlg function displays dialog boxes during the connection operation to provide feedback to the user about the progress of the operation. For example, the dialog boxes might indicate when the operation is dialing, when it is authenticating the user's credentials on the remote server, and so on. The dialog boxes also provide a Cancel button for the user to terminate the operation.

RasDialDlg returns when the connection is established, or when the user cancels the operation.

The following sample code dials the entry in the default phone-book specified by the variable lpszEntry.

Note  This simple sample is intended to run on Windows Vista and later versions of Windows. Please be aware the call to sizeof(RASENTRY) will return a different value depending on what version of the operating system the code is being run. Please take steps to ensure this is handled appropriately.
#include <windows.h>
#include <stdio.h>
#include "ras.h"
#include "rasdlg.h"
#include <tchar.h>
#include "strsafe.h"


DWORD __cdecl wmain(){

LPTSTR lpszEntry = L"EntryName";
LPTSTR lpszphonenumber = L"5555555";
LPTSTR lpszdevicename = L"Modem";
LPTSTR lpszdevicetype = RASDT_Modem;

// Allocate heap memory and initialize RASENTRY structure
LPRASENTRY lpentry = (LPRASENTRY)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RASENTRY));
// Allocate heap memory and initialize RASDIALDLG structure

if (lpentry == NULL || lpInfo == NULL){
    wprintf(L"HeapAlloc failed");
    HeapFree(GetProcessHeap(), 0, lpentry);
    HeapFree(GetProcessHeap(), 0, lpInfo);
    return 0;

// The RASDIALDLG and RASENTRY dwSize members have to be initialized or the RasDialDlg()
// RasSetEntryProperties() APIs will fail below.
lpInfo-&gt;dwSize = sizeof(RASDIALDLG);
lpentry-&gt;dwSize = sizeof(RASENTRY);
lpentry-&gt;dwFramingProtocol = RASFP_Ppp;
lpentry-&gt;dwfOptions = 0;
lpentry-&gt;dwType = RASFP_Ppp;
dwError |= StringCchCopyN(lpentry-&gt;szLocalPhoneNumber, RAS_MaxPhoneNumber, lpszphonenumber, PHONE_NUMBER_LENGTH);
dwError |= StringCchCopyN(lpentry-&gt;szDeviceName, RAS_MaxDeviceName, lpszdevicename, DEVICE_NAME_LENGTH);
dwError |= StringCchCopyN(lpentry-&gt;szDeviceType, RAS_MaxDeviceType, lpszdevicetype, DEVICE_TYPE_LENGTH);

if (dwError != S_OK){
    wprintf(L"Structure initilization failed: Error = %d\n", dwError);
    HeapFree(GetProcessHeap(), 0, lpentry);
    HeapFree(GetProcessHeap(), 0, lpInfo);
    return 0;

// Validate the new entry's name
dwError = RasValidateEntryName(NULL, lpszEntry);
if (dwError != ERROR_SUCCESS){
    wprintf(L"RasValidateEntryName failed: Error = %d\n", dwError);
    HeapFree(GetProcessHeap(), 0, lpentry);
    HeapFree(GetProcessHeap(), 0, lpInfo);
    return 0;

// Create and set the new entry's properties
dwError = RasSetEntryProperties(NULL, lpszEntry, lpentry, lpentry-&gt;dwSize, NULL, 0);
if (dwError != ERROR_SUCCESS){
    wprintf(L"RasSetEntryProperties failed: Error = %d\n", dwError);
    HeapFree(GetProcessHeap(), 0, lpentry);
    HeapFree(GetProcessHeap(), 0, lpInfo);
    return 0;

// Connect using the new entry
nRet = RasDialDlg(NULL, lpszEntry, NULL, lpInfo);
if (nRet != TRUE){
    wprintf(L"RasDialDlg failed: Error = %d\n", lpInfo-&gt;dwError);

// Clean up: delete the new entry
dwError = RasDeleteEntry(NULL, lpszEntry);
if (dwError != ERROR_SUCCESS){
    wprintf(L"RasDeleteEntry failed: Error = %d\n", dwError);

HeapFree(GetProcessHeap(), 0, lpentry);
HeapFree(GetProcessHeap(), 0, lpInfo);

return 0;



Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header rasdlg.h
Library Rasdlg.lib
DLL Rasdlg.dll

See Also



Remote Access Service (RAS) Overview

Remote Access Service Functions