VC implements dial-up network programs, you know that in Netants, Download Expert and other software, there is a function of time dial-up network download software. The general user's dial-up Internet is used to use Windows Remote Access Service (RAS, Remote Access Service). Here is the implementation of its implementation under Visual C . Visual C provides us with a "ras.h" header file containing the RAS API declaration. To implement a dial-up function in the program, the rough process is as follows: 1. Use the MODEM dial-up to connect to the Rasdial function. That the following statement: DWORD Ras Dial (LPRASDIALEXTENSIONS lpRas DialExtensions, LPCTSTR lpszPhonebook, LPRASDIALPARAMS lp Ras DialParams, DWORD dw Notifier Type, LPVOID lpv Notifier, LPHRASCONN lph Ras Conn) Parameter Description: lpRasDialExtensions and lpszPhonebook: only valid under Windows NT, the Windows 95 Under the two parameters are ignored. LPRASDIALPARAMS: This parameter is important, it points to a RasdialParams structure, which contains the following members: dwsize: should be set to sizeof (rasdialparams); SzenTryName and SzphonEnumber: These two parameters are connected, SzenTryName can specify the connection to build For example, "My Connection", etc., this is the connection to the user has been established in the "Dial Network". At this time, MODEM will call you the ISP number set in "My Connection". At this point, the SzphonEnumber member is set to empty string "" "If you want to specify the ISP number to make yourself in the program, SizentryName It can be set to empty string "", at this time, SzphonEnumber should be set for your ISP number (169, 663, etc.), especially, for the case where the phone card is used online, can be set to "201,, account, password # ,, ",", "," said that the pause is a period of time (to wait for a confirmation account, password, etc.), you can adjust it according to the line status of your location. SzcallbackNumber, szdomain: set to empty string "" Szusername, SZPassword: Log in to the username and password. Such as 169 utility account guest, guest. DwiniFiertype: specified by the window or the callback function to process the confirmation message. We can get the current state of the Rasdial process by confirmation messages. Such as "Open Segment", "Positive User Name and Password", etc. It can also be set to null. Dwnotifier: Specifies the window or callback function of the processing confirmation message. It can also be set to null. Lphrasconn: Point to a variable of a type HRASCONNNNN The RasDial is stored in the variable that the RAS connection is stored before calling Rasdial, and Rasdial is stored in the variable it pointing. We can also disconnect it through this handle.
The connection can be established as long as the RasDial function is called in the appropriate location in the program. 2. Licensing the message to get the current state of the dialing process. We handle confirmation messages with a specified window to explain how to get the current state of the dialing process. Add in the implementation code of the dialog class (or view class, etc.) to handle the confirmation message: Const uint wm_rasevent = :: registerWindowMessagea (rasdialevent); manually add message mapping in the Message Map: (**** is your defined conversation frame name) BEGIN_MESSAGE_MAP (****, CDialog) // AFX_MSG_MAP (****) ...... ON_REGISTERED_MESSAGE (WM_RASEVENT, OnRasDialEvent) (<- added sentence) // AFX_MSG_MAP END_MESSAGE_MAP () member function to process the message added: LRESULT CDialInfo :: OnRasDialEvent (WPARAM wp, LPARAM lp) {RASCONNSTATE rasstate = (RASCONNSTATE) wp; CListBox * info = (CListBox *) GetDlgItem (IDC_INFOLIST); // with ListBox control (ID of IDC-iNFOLIST) to display status) Switch (rasstate) {case ras_openport: info → addstring (_T ("Open Port ...")); break; case rascs_portopened: info → addstring (_T ("port is open.")); break; case rascs_connectdevice: info → addstring (_T ("Connection Equipment ...")); Break; Case Rascs_DeviceConnected: Info → AddString (_T ("Device is connected.")); Break; Case Rascs_Authenticate: Info → AddString (_T ("Verify User and Password") ); Case rascs_authenticated: info → addstring (_T ("pass")); break; case rascs_connected: info-> addstring (_T ("Connected")); Reak; Case Rascs_disconnected: Info-> ad DSTRING (_T ("Connect")); m_hrasconn = null; // can define a member variable m_hrasconn type HRASCONN to save the Handle of the RAS connection. // Use the pointer to M_hrasconn as the LPHRASCONN parameter when calling Rasdial. // Since the connection handle is saved with m_hrasconn, it should be reset to null. Break; default: return (LRESULT) 0;} Return (LRESULT) 0;} 3. Disconnect: IF (m_hrasconn! = Null ) {Rashangup (m_hrasconn); m_hrasconn = null; m_ondial = true;: sleep (2000);} Note: You may notice that the SLEEP function in the above code is required. It takes a certain time to disconnect the connection.