The Code Project Click here for Dundas Software's TCP/IP Development Kit
Home >> Internet & Network >> Dialup

Opening a Dial-Up connection
By Mileta Radenovic

How to open a new dialup connection using RasDial 
 Beginner
 VC6, Win98, MFC
 Posted 14 Jan 2000
Articles by this author
Send to a friend
Printer friendly version
Latest Articles Logon Message Boards Submit an Article
Broken links? Email us!
18 users have rated this article. result:
3.5 out of 5.

  • Download demo project - 10 Kb
  • There is a code for Dial-Up connection. Alexander Fedorov discusses in his article Calling RasHangUp without errors how to disconnect a dial-up connection. This is other part of same problem (accessing the internet via phone line). This task can be done by using the CInternetSession::GetFtpConnection() function for example, but only if all parameters in the dial-up dialog are present (but then you can't set the username, password and phone number programatically).

    To use this function you must include the "ras.h" and "raserror.h" header files and link with rasapi32.lib.

    bool DialUp() 
    {    
        // Fill RASDIALPARAMS structure
        RASDIALPARAMS rdParams;
        rdParams.dwSize = sizeof(RASDIALPARAMS);
        rdParams.szEntryName[0] = '\0';
        lstrcpy(rdParams.szPhoneNumber, szPhoneNumberToDial);
        rdParams.szCallbackNumber[0] = '\0';
        lstrcpy( rdParams.szUserName, szUserName );
        lstrcpy( rdParams.szPassword, szPassword );    
        rdParams.szDomain[0] = '\0';
    
        HRASCONN hRasConn = NULL;
        DWORD dwRet = RasDial( NULL, NULL, &rdParams;, 0L, NULL, &hRasConn; );
    
        // Everything OK?
        if (dwRet == 0)  
            return true;    
    
        // Error occurred - get error description and alert user
        char  szBuf[256];
        if (RasGetErrorString( (UINT)dwRet, (LPSTR)szBuf, 256 ) != 0 )
            wsprintf( (LPSTR)szBuf, "Undefined RAS Dial Error (%ld).", dwRet );
        RasHangUp( hRasConn );
        AfxMessageBox( NULL, (LPSTR)szBuf, "Error", MB_OK | MB_ICONSTOP );
    
        return false;
    }
    

    Note that here I'm using the synchronous version (the fifth parameter of RasDial() is NULL). The updated version can use a pointer to the RasDialFunc() function instead, and then RasDial() returns immediately and calls RasDialFunc() when WM_RASDIALEVENT occurs.

    [Top] Rate this Article for us!     PoorExcellent  
    Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Dynamic' from the View dropdown and hit 'Refresh'
     Keyword Filter
     View   Per page   Messages since
    New threadMessages 1 to 2 of 2 (Total: 2)First | Prev | Next | Last
    Subject 
    Author 
    Date 
      RE: DialUp
    Martijn Hoogendoorn 16:42 6 Mar 00 
      Make link dynamic
    Brad Bruce 11:25 15 Jan 00 
    Last Visit: 12:00 Friday 1st January, 1999First | Prev | Next | Last

    Home >> Internet & Network >> Dialup
    last updated 14 Jan 2000
    Article content copyright Mileta Radenovic, 2000
    everthing else © CodeProject, 1999-2001.
    The Code Project Click here for Dundas Consulting - experts in MFC, C++, TCP/IP and ASP