Dial-up Internet access through MODEM is still the way most individual netizens choose to access the Internet. If we can enable dial-up connections in our applications (such as the automatic dial-up function in the IE browser program), it will undoubtedly be more convenient for our software users (no need to switch applications and run dial-up networks) and improve the friendliness of our software. thereby improving the competitiveness of software.
Under WIN9X, if dial-up networking is installed, there will be two dial-up network management libraries, RasApi32.DLL and RasApi16.DLL, under the system directory System of the WINDOWS system. We can use the functions in them to create and modify dial-up connections, and Dial-up Internet access using a designated dial-up connection.
1. Create a new dial-up connection
When a dial-up connection has been established in the WIN9X system, the existing dial-up connection can be used. If there is no dial-up connection, you need to create a new dial-up connection. The corresponding function is provided in RasAPI, its function name is RasCreatePhonebookEntryA, and the function prototype is:
function RasCreatePhonebookEntryA( hwnd : THandle;lpszPhonebook: pchar ) : DWord;
stdcall; { located in interface section}
function RasCreatePhonebookEntryA; external 'Rasapi32.dll';{ located in implementation section}
parameter:
hwnd (THandle): The handle of the parent window of the new dial-up connection window, which can be the Handle of TForm or the NIL table; Windows Desktop (DeskTop)
lpszPhonebook (pchar): Phonebook name, has no effect under Win9X, can be set to an empty string
Function return value:
0 indicates successful execution; otherwise, it is an error.
Below is an example of creating a new dial-up connection.
{Create a new dial-up connection}
PRocedure TForm1.Button1Click(Sender: TObject);
var
dwResult: DWORD;
begin
//Create a new 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 properties of the specified dial-up connection
If the user needs to modify the attributes of the dial-up connection such as phone number, country and area code, connection method, server type, etc., he can use the RasAPI function to achieve this. The function name is RasEditPhonebookEntryA, and the function prototype is:
function RasEditPhonebookEntryA( hwnd : THandle; lpszPhonebook: pchar;
lpszEntryName: pchar ) : DWORD;stdcall; { located in the interface part}
function RasEditPhonebookEntryA; external 'Rasapi32.dll';{ located in the implementation section}
parameter:
hwnd (THandle): The handle of the parent window of the new dial-up connection window, which can be the Handle of TForm, expressed as NIL
Windows Desktop(DeskTop)
lpszPhonebook (pchar): Phonebook name, has no effect under Win9X, can be set to an empty string
lpszEntryName: (pchar): The name of the dial-up connection to be modified, such as '163', '169', etc.
Function return value:
0 indicates successful execution; otherwise, it is an error.
The following is an example of modifying the properties of a specified dial-up connection.
{Modify the specified dial-up connection properties}
procedure TForm1.Button2Click(Sender: TObject);
var
dwResult: DWORD;
strDialName : string;
begin
strDialName := '163';//Set the name of the dial-up connection to 163
//Specify and modify the properties 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 + 'Success!')
else
memo1.lines.add('Modify dial-up connection' + strDialName + 'Failed!')
end;
3. Obtain the dial-up connection names available in the current system
In order for the user to choose to dial using a dial-up connection, we need to get the name of the dial-up connection that has been established in the system. After establishing a dial-up connection, WIN9X writes the name and attributes of the dial-up connection in the registry. We can obtain the dial-up connection names available in the current system and the default connection name set in Internet Explorer from the registry.
Under HKEY_USERS.DefaultRemoteaccessAddresses in the registry, the names of dial-up connections that have been established in the dial-up network and their attribute settings are listed. The name of each item is the name of the available dial-up connection; the value of each item is the name of the available dial-up connection. Dial-up connection property settings. We only need to read the name of each project to obtain the dial-up connection names available in the current system.
If the default connection name is set in Internet Explorer (View => Internet Options => Connection => Connection => Settings => Use the following dial-up network connection), then under HKEY_USERS.DefaultRemoteAccess in the registry, there is a string type Key value, the key value name is InternetProfile, and its value is the default connection name set in Internet Explorer.
The following is an example of obtaining the names of dial-up connections available on the current system.
{Note that the Registry unit is added to Uses for operating the registry}
{Get the dial-up connection names 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;//The root key is set to HKEY_USERS
//If there are subkeys.DefaultRemoteAccessAddresses
if OpenKey('.DefaultRemoteAccessAddresses',false) then
GetValueNames( stringsTemp );//Read out the name of each item, that is, the dial-up connection name
CloseKey;
end;
//Dial-up connections available in the current system
memo1.lines.add( '******************There are'+ IntToStr( stringsTemp.count ) in the current system
+'The 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('.DefaultRemoteAccess',false) then
memo1.lines.add( 'The default connection name set in Internet Explorer is' +
registryTemp.ReadString('InternetProfile') );
//release memory
registryTemp.free;
stringsTemp.free;
end;
4. Dial using the specified dial-up connection
The purpose of the above three tasks is to dial-up Internet access. Now let's take a look at how to use a designated dial-up connection to dial-up Internet access. The best way is to call the dial-up network service of WIN9X, which is to run the ready-made program under WIN9X.
In a 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 dial-up Internet access using a specified dial-up connection.
{Dial-up Internet access using the specified dial-up connection}
procedure TForm1.Button4Click(Sender: TObject);
var
strDialName : string;
begin
strDialName := '163';//Set the name of the dial-up connection to 163
memo1.lines.add( '****************Use dial-up connection' + strDialName
+'Realize dial-up Internet access******************');
winexec( PChar('rundll32.exe rnaui.dll,RnaDial ' + strDialName),SW_SHOWNORMAL);
end;
The above program was debugged and passed under PWIN98+Delphi3.0.