{ Try to establish RAS connection with specified name. EntryName -
an entry in default phonebook to be used for dial-up. Notes:
a) This call is synchronous (i.e. will not return until the connection
is established or failed) and hence, may take some time
(sometimes tens of seconds).
b) The function uses no dial extension, and uses default phonebook. }function RasMakeDialupConnection(const EntryName: string): Boolean;
var
dwRet: Dword;
DialParams: TRasDialParams;
hRas: HRASCONN;
bPwd: Boolean; // was the password retrievedbegin
uLastErr := 0; // Prepare dial parameters
FillChar(DialParams, SizeOf(DialParams), 0);
DialParams.dwSize := SizeOf(DialParams);
StrPLCopy(@(DialParams.szEntryName[0]), EntryName,
SizeOf(DialParams.szEntryName));
hRas := 0; // must do that before calling RasDial// Try to retrieve user name/passowrd.// We continue even if RasGetEntryDialParams returns error, because// in next call RasDial will just try with empty user name/password
bPwd := False;
RasGetEntryDialParams(nil, @DialParams, bPwd);
// Call RAS API. In this particular case RasDial will not return until// the connections is established or failed to establish.
dwRet := RasDial(nil, nil, // no dial extensions, default phonebook
@DialParams,
0, // ignored herenil, // do not use callback - the call is synch
hRas); // receives connection handle
Result := dwRet = 0; // Connection failed... if not Result then begin// In some cases hRas may be non-zero and the connection port// is still opened. It is a Windows semi-bug/semi-feature.// So I must try to closeif hRas <> 0 then
RasHangupConnection(hRas);
// RasHangup may reset uLastErr, but we need the value // returned from RasDial
uLastErr := dwRet;
end;
end;