Implementing RAS dialing in the application

Source: Internet
Author: User
Tags error code

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)
{
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.