Implement Ras dialing in applications

Source: Internet
Author: User
Implement Ras dialing in applications

Wang Tao Remote Access Service (RAS) is one of the system services provided by the Windows NT operating system. It allows a separate computer to access the network through a telephone line, or connects two local networks through two Ras pairs. This service enables remote computer endpoints to connect to the network at a low cost. Due to the extensive use of the Windows NT operating system, the remote access service function is also widely used in many specific applications, you can use the remote access service to share remote resources. To connect to the remote access service, you only need to dial the dial-up network from the remote client, and then stop the connection after you execute the stop operation. You can use the mouse to operate the dial-up network in Windows 95. But sometimes we want to make the RAS dial-up and stop-up invisible to users in the application, then we need corresponding program control to implement Ras dial-up and stop-up. Windows 95 provides the API function rasdial, which calls the dial-up network established in the system to complete Ras dialing, and also provides the API function rashangup to disconnect. Rasdial: DWORD rasdial (lprasdialextensions iprasdialextensions, lptstr ipszphonebo OK, lprasdialparams iprasdialparams, DWORD dwnotifiertype, lpvoid ipvnotifier, l phrasconn iphrasconn) the first parameter of this function is the pointer to the rasdialparams struct. It provides the parameter for configuring Ras dialing. The second parameter is the callback function executed after dialing; the 6th parameters are lphrasconn pointers. After the dial-up connection is established, the handle of the connection is returned. The other three parameters are null. If the function is successfully called, zero is returned. Otherwise, the error code is returned. The meaning of the error code can be found in the header file raserror. h. Rasdialparams struct contains seven data members: dwsize, szentryname, szphonenumber, szcallbacknumber, szusername, szpassword, and szdomain. Their functions are shown in the right table. To use the rashangup function for hanging up a connected connection, the required parameter is the connection handle of the connection. The following is an example of using VC to complete Ras dialing. Assume that the phone number of the internal extension connected to the Ras-side NT Server is "22". The procedure is as follows: 1. configure the modem and create a connection named dial in the dial-up network of Windows 95. 2. Create a visual C Application Framework and add the rasapi32.lib static library to the application in setting. 3. Create a dialog box and add two buttons, one for dialing and the other for hanging up. 4. add the following code to the response function with the mouse clicked: 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) I F (dwret! = 0) {// deal with error...} 5. add the following code before this response function: void winapi rasdialfunc (uint unmsg, rasconnstate, DWORD dwerror) {} 6. add the following code to the response function after you click the stop button: DWORD dwret; dwret = rashangup (hrasconn); 7. finally, compile and execute the program. Table 1 rasdialparams struct data member table (by wangtaowt@yahoo.com)

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.