Remote Access Service (RAS) is one of the system services provided by the WindowsNT operating system, which enables a separate computer to be connected to a network through a telephone line, or two LANs connected through two RAS pairs. The functionality of this service enables remote computer endpoints to connect to the network at a lower cost.
Because of the extensive use of the WindowsNT operating system, the remote Access Service function is also widely used, and in many specific applications, remote access services have been used to realize the function of resource sharing. Connected to the remote Access service, as long as the dial-up network from the remote client can be done, the execution hangs on the end of the connection, the mouse operation Windows95 dial-up network can be directly dialed and hung up. But there are times when we want Ras dialing and hanging up in the application to be invisible to the user, then the appropriate program control is needed to implement the RAS dialing and hanging.
WINDOWS95 provides API function Rasdial, invokes the established Dial-up networking connection in the system, completes RAS dialing, and also provides API functions Rashangup disconnect. Rasdial's prototype is as follows:
DWORD RasDial (lprasdialextensions iprasdialextensions,lptstr ipszphonebook,lprasdialparams Iprasdialparams,dword Dwnotifiertype,lpvoid ipvnotifier,lphrasconn Iphrasconn)
The 3rd parameter of this function is a pointer to the RASDIALPARAMS structure, which provides parameters for configuring RAS dialing, and the 5th parameter is a callback function that executes after dialing completes; the 6th parameter is a lphrasconn pointer, and the handle to the connection is returned after the dial-up connection is established. ; the other 3 parameters are null. A function call returns an error code if it succeeds in returning zero, and the meaning of this error code can be found in the header file Raserror.h.
The RASDIALPARAMS structure consists of 7 data members: dwsize, Szentryname, Szphonenumber, Szcallbacknumber, szUserName, Szpassword, and Szdomain, They function as shown in the right table.
To hang a dialed connection using the Rashangup function, the required parameter is the connection handle for this connection. The following is an example of using VC to complete RAS dialing, where we assume that the phone number of the internal extension of the RAS-side NT Server connection is "22", as follows:
1. Configure your modem, and then establish a connection named dial in Windows95 dial-up networking.
2. Establish a VISUALC application framework for adding Rasapi32.lib static libraries to applications in setting.
3. Create a new dialog box with two buttons on it, one for dialing and one for hanging up.
4. Add the following code to the response function of the mouse click and Dial button:
Rasdialparams Rdparams;
DWORD Dwret;
Rdparams.dwsize=sizeof (Rasdialparams);
strcpy (Rdparams.szentryname, "dial");
strcpy (Rdparams.szphonenumber, "22");
strcpy (Rdparams.szcallbacknumber, "*");
strcpy (Rdparams.szusername, "dial");
Rdparams.szpassword[0]= ' ";
strcpy (Rdparams.szdomain, "dial");
Hrasconn=null;
Dwret=rasdial (null,null,&rdparams,0l, (Rasdialfunc) rasdialfunc,&hrasconn);
if (dwret!=0)
{
Dealwitherror ...
}
5. Add the following code before this response function:
VOID WINAPI Rasdialfunc (UINT unmsg,rasconnstate rasconnstate,dword dwerror)
{
}