Making dial-up connection

Submitted by date of submission user level 

Mahesh Chand July 10, 2000 Intermediate 

Dialup Connection

This sample tells you how to make a dialup connection using WinInet APIs. I have used only two API function in this sample: InternetDial() and InternetHangUp().

InternetDial() displays a modal dialog box which you see when you use dialup connection from your desktop. After that it starts a connection to the internet. InternetHangUp() function disconnects internet connection. 

Here are steps to setup a dialup connection:

Create an MDI application. Name this project Dial. 

Add two variables bInternetConnected of boolean type and dwInternetConnection of type DWORD. 

Add a member function of CDialApp application class called Connect() and write this code: 

BOOL CDialApp::Connect()

{

DWORD dwResult = ::InternetDial( AfxGetMainWnd()->GetSafeHwnd(), "", INTERNET_AUTODIAL_FORCE_ONLINE, &dwConnection, 0 );

if ( dwResult == ERROR_SUCCESS )

bConnected = TRUE;

else

bConnected = FALSE;

return bConnected;

}

Call this Connect() from InitInstance() of application class.  

            bConnected = Connect();

Now override application class's ExitInstance() using class wizard and write this code: 

int CDialApp::ExitInstance() 

{

int nRes = CWinApp::ExitInstance();

if ( bConnected )

::InternetHangUp( dwConnection, 0 );

return nRes;

}

 

Build and Run your application.

That's it folks.