RAS: Call and HangUp a inet connection  

Send By: Jesús Fernández Hernández
Web : N.A.
Email: jfh69@airtel.net
Date: 21/04/00

Tip accessed 420 times

 


Put this two functions that use the RasApi.PAS unit from the tip:

[103] - Disconnect the internet connection


 function OpenConnection( PhoneNumber: String; UserName: String; Password: String; EntryName: String; Var rasConn:
 HRASConn ): DWORD;
 Var
    lpRasDialParams : PRASDIALPARAMS;
 Begin
    GetMem( lpRasDialParams, SizeOf( lpRasDialParams^ ) );
    lpRasDialParams^.dwSize := SizeOf( lpRasDialParams^ );
    StrCopy( @(lpRasDialParams^.szEntryName ), PCHAR( EntryName ) );
    StrCopy( @(lpRasDialParams^.szUserName) , PCHAR( UserName ) );
    StrCopy( @(lpRasDialParams^.szPassword ), PCHAR( Password ) );
    StrCopy( @(lpRasDialParams^.szPhoneNumber ), PCHAR( PhoneNumber ) );
    StrCopy( @(lpRasDialParams^.szCallbackNumber ), PCHAR( '' ) );
    StrCopy( @(lpRasDialParams^.szDomain ), PCHAR( '' ) );

    Result := RasDial( Nil { lpRasDialExtensions : PRASDIALEXTENSIONS ; pointer to function extensions data },
                       Nil { lpszPhonebook: PChar;        pointer to full path and filename of phonebook file },
                       lpRasDialParams { pointer to calling parameters data},
                       0 { dwNotifierType : DWORD;       specifies type of RasDial event handler},
                       0 { lpvNotifier: DWORD;        specifies a handler for RasDial events},
                       rasConn { pointer to variable to receive connection handle}
                     );
    FreeMem( lpRasDialParams );
 End;

 Function CloseConnection( rasConn: HRASConn ): Boolean;
 Begin
    If rasConn <> 0
    Then Result := ( RasHangUp(rasConn) = 0 )
    Else Result := True;
 End;



For test them, make this in a form:



 Var
   rasConn: HRASConn;

 procedure TForm1.ButtonAbrirClick(Sender: TObject);
 begin
         rasConn := 0;
         Edit1.Text := IntToStr( OpenConnection( '', '', '', '',
 rasConn ) );
         Edit2.Text := IntToStr( rasConn );
 end;

 procedure TForm1.ButtonCerrarClick(Sender: TObject);
 begin
    CloseConnection( rasConn );
 end;