Using modem to dial up the Internet is still the method that most individual netizens choose to access the Internet. if we can start a dial-up connection in our applications (such as the auto-dial function in the IE browser), it will undoubtedly be convenient for our software users (no need to switch the application, to improve the friendliness of our software and improve the competitiveness of the software.
If a dial-up network is installed in Win9x, two dial-up network management libraries rasapi32.dll and rasapi16.dll are available in the system directory of windows, we can use the functions to create and modify dial-up connections, and use the specified dial-up connection for dial-up access.
1. Create a dial-up connection
When a dial-up connection has been established in the Win9x system, a ready-made dial-up connection can be used. If there is no dial-up connection, you need to create a new dial-up connection. Rasapi provides a function named rascreatephonebookentrya. The function is prototype:
Function rascreatephonebookentrya (hwnd: thandle; lpszphonebook: pchar): DWORD;
Stdcall; {In interface}
Function rascreatephonebookentrya; External 'rasapi32. dll '; {in Implementation}
Parameters:
Hwnd (thandle): the handle of the parent window of the new dial-up connection window, which can be the handle of tform and the NIL table; Windows Desktop)
Lpszphonebook (pchar): the name of the phone book. It does not work in Win9x and can be set as a null string.
Function return value:
0 indicates that the execution is successful; otherwise, it indicates an error.
The following is an example of creating a dial-up connection.
{New dial-up connection}
Procedure tform1.button1click (Sender: tobject );
VaR
Dwresult: DWORD;
Begin
// Create a dial-up connection in the current window
Dwresult: = rascreatephonebookentrya (handle ,'');
If dwresult = 0 then
Memo1.lines. Add ('new dial-up connection successful! ')
Else
Memo1.lines. Add ('new dial-up connection failed! ')
End;
2. Modify the attributes of a specified dial-up connection
If you need to modify the attributes of a dial-up connection, such as the phone number, country and area number, connection method, and server type, you can use the rasapi function. Its function name is raseditphonebookentrya, and its prototype is:
Function raseditphonebookentrya (hwnd: thandle; lpszphonebook: pchar;
Lpszentryname: pchar): DWORD; stdcall; {In interface}
Function raseditphonebookentrya; External 'rasapi32. dll '; {in Implementation}
Parameters:
Hwnd (thandle): the handle of the parent window of the new dial-up connection window. It can be the handle of tform, which is represented by nil.
Windows Desktop)
Lpszphonebook (pchar): the name of the phone book. It does not work in Win9x and can be set as a null string.
Lpszentryname :( pchar): name of the dial-up connection to be modified, such as '123456' and '1234568 '.
Function return value:
0 indicates that the execution is successful; otherwise, it indicates an error.
The following is an example of modifying the attributes of a specified dial-up connection.
{Modifying the attributes of a specified dial-up connection}
Procedure tform1.button2click (Sender: tobject );
VaR
Dwresult: DWORD;
Strdialname: string;
Begin
Strdialname: = '000000'; // set the name of the dial-up connection to 163.
// Modify the attributes of the dial-up connection in the current window
Dwresult: = raseditphonebookentrya (handle, '', pchar (strdialname ));
If dwresult = 0 then
Memo1.lines. Add ('modify dial-up connection' + strdialname + 'successfully! ')
Else
Memo1.lines. Add ('modify dial-up connection' + strdialname + 'failed! ')
End;
3. Obtain the name of available dial-up connections in the current system
To allow users to select a dial-up connection for dialing, we need to obtain the name of the dial-up connection established in the system. After a dial-up connection is established, Win9x writes the name and attributes of the dial-up connection in the registry, you can obtain the available dial-up connection names and the default connection names in Internet Explorer from the registry.
HKEY_USERS /. under default/RemoteAccess/addresses, the names and attribute settings of the dial-up connections established in the dial-up network are listed. The names of each project are the names of available dial-up connections; the destination value is the property setting of each dial-up connection. we only need to read the name of each item to obtain the name of the dial-up connection available in the current system.
If the default connection name is set in Internet Explorer (view = Internet Options = connection = use the following dial-up network connection ), the HKEY_USERS /. under default/RemoteAccess, there is a string-type key value named internetprofile. Its value is the default connection name set in Internet Explorer.
The following is an example of obtaining the name of a dial-up connection available in the current system.
{Note: Add a Registry Unit to uses to operate the Registry}
{Obtain the name of the dial-up connection available in the current system}
Procedure tform1.button3click (Sender: tobject );
VaR
Registrytemp: Tregistry;
Stringstemp: tstringlist;
Intindex: integer;
Begin
Registrytemp: = Tregistry. Create;
Stringstemp: = tstringlist. Create;
With registrytemp do
Begin
Rootkey: = HKEY_USERS; // set the root key to HKEY_USERS.
// If the sub-key. Default/RemoteAccess/addresses exists
If openkey ('. Default/RemoteAccess/SES SSEs', false) then
Getvaluenames (stringstemp); // read the name of each project, that is, the name of the dial-up connection.
Closekey;
End;
// Available dial-up connections in the current system
Memo1.lines. Add ('********************' + inttostr (stringstemp. Count) in the current system)
+ 'Available dial-up connections are as follows ****************');
For intindex: = 0 to stringstemp. Count-1 do
Memo1.lines. Add (stringstemp. Strings [intindex]);
// List the default connection names set in Internet Explorer
If registrytemp. openkey ('. Default/remoteaccess', false) then
Memo1.lines. Add ('default connection name set in Internet Explorer '+
Registrytemp. readstring ('internetprofile '));
// Release the memory
Registrytemp. Free;
Stringstemp. Free;
End;
4. Use the specified dial-up connection for dialing
The purpose of the above three tasks is to dial up the Internet. Now let's take a look at how to use the specified dial-up connection to dial the internet. The best way is to call Win9x's dial-up network service and run the ready-made Program Under Win9x.
In the Delphi program, you can use the following code to implement dial-up Internet access:
Winexec('rundll32.exe rnaui. dll, rnadial 163 ', sw_shownormal );
The last parameter "163" in the string is the name of the dial-up connection.
The following is an example of using a specified dial-up connection for dial-up access.
{Use the specified dial-up to connect to the dial-up Internet}
Procedure tform1.button4click (Sender: tobject );
VaR
Strdialname: string;
Begin
Strdialname: = '000000'; // set the name of the dial-up connection to 163.
Memo1.lines. Add ('******************** use dial-up connection' + strdialname
+ 'Achieve dial-up Internet access ****************');
Winexec (pchar('rundll32.exe Rui. dll, rnadial '+ strdialname), sw_shownormal );
End;
The above program is successfully debugged under pwin98 + Delphi3.0.