Click here to Skip to main content
15,867,874 members
Articles / Desktop Programming / MFC
Article

Opening a Dial-Up connection

Rate me:
Please Sign up or sign in to vote.
3.89/5 (9 votes)
13 Jan 2000 149.1K   2.9K   28   16
How to open a new dialup connection using RasDial
  • 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.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    Software Developer (Senior)
    Canada Canada
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    Suggestionyes this can also be tricky in SEO Pin
    Ranvir Sharma25-Dec-13 23:41
    Ranvir Sharma25-Dec-13 23:41 
    GeneralProblem with proxy Pin
    mahila6-Jan-06 23:18
    mahila6-Jan-06 23:18 
    GeneralNice Pin
    gamitech12-Sep-04 11:51
    gamitech12-Sep-04 11:51 
    GeneralWin 98 & RasDial Pin
    shoshana13-Jul-04 0:55
    shoshana13-Jul-04 0:55 
    GeneralRe: Win 98 & RasDial Pin
    leechangjun29-Mar-11 21:51
    leechangjun29-Mar-11 21:51 
    GeneralRegarding creating Dialup via Visual Basic Pin
    autometa2-Feb-04 23:31
    autometa2-Feb-04 23:31 
    GeneralNewer ras.h Pin
    nikouhl6-Aug-03 5:26
    nikouhl6-Aug-03 5:26 
    GeneralGetting the IP address from the Remote PC Pin
    Leon van Wyk10-Apr-03 1:40
    professionalLeon van Wyk10-Apr-03 1:40 
    GeneralPlease help Pin
    bowetech14-Feb-03 16:25
    bowetech14-Feb-03 16:25 
    GeneralRe: Please help Pin
    Leon van Wyk10-Apr-03 1:13
    professionalLeon van Wyk10-Apr-03 1:13 
    GeneralThis code overwrites original PhoneBook Pin
    Tili18-Jul-02 15:57
    Tili18-Jul-02 15:57 
    QuestionWhat if i dial ¶ÌÈ©¥ Pin
    21-Feb-02 18:56
    suss21-Feb-02 18:56 
    GeneralWindows 98 as dial-up server Pin
    20-Feb-02 16:01
    suss20-Feb-02 16:01 
    GeneralRe: Windows 98 as dial-up server Pin
    Leon van Wyk10-Apr-03 1:17
    professionalLeon van Wyk10-Apr-03 1:17 
    GeneralRE: DialUp Pin
    Martijn Hoogendoorn6-Mar-00 10:42
    sussMartijn Hoogendoorn6-Mar-00 10:42 
    GeneralMake link dynamic Pin
    Brad Bruce15-Jan-00 5:25
    Brad Bruce15-Jan-00 5:25 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.