• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

DialUP Networking Program

Can you tell me how to make a simple dial-up networking to an ISP using MFC ?
0
hiap_ho
Asked:
hiap_ho
  • 15
  • 9
  • 5
  • +1
1 Solution
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

Have u tried with 'Dialer'?. The sample is available for it in vc++ online help. Just type dialer in find window and u will get the sample.

VinExpert
0
 
eugene007Commented:
You could go to this website...you answer could be over here :

http://www.codeguru.com/network/network_toc.shtml
0
 
jhanceCommented:
Please reject eugene007's answer and I'll be happy to answer this completely with source code.

In the mean time, the short answer is to use RasDial() in the Win32 API.  This is not an MFC problem as there are no MFC classes dealing with RAS or DUN.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
eugene007Commented:
ops...sorry..i forgot to select the comment radio button..heheh..:)
0
 
eugene007Commented:
I think my URL has the answer...to what jhance has proposed..:)
0
 
eugene007Commented:
It also has the complete source code well as a running download program..:)
But you have to look at it first before you make any evaluation..:)
0
 
eugene007Commented:
Regarding about the assignment of points...it does not matter...its up to you...i just came across your question so i desided to help. As we know to be a champion of knowledge is to share knowledge..:) That is my principal..:).
I am still learning..:)

Regards

Eugene
0
 
hiap_hoAuthor Commented:
Thanks for the URL link given to me by Eugene, however the link is not very helpful since most of the code are created in Visual Basic, moreover I have tried one of the code, and it's not working. But I appreciate your help.
0
 
hiap_hoAuthor Commented:
I think I own Eugene an apology anyway since my question is not complete at the first place... sorry...
but I'm trying to do it in Visual C++ 6
0
 
hiap_hoAuthor Commented:
Can you tell me more about it ?
0
 
jhanceCommented:
Yes, I'll be happy to post an example but it will have to be later today, I'm just having to leave at the moment...
0
 
hiap_hoAuthor Commented:
OK no problem
I cannot test it now anyway
have to wait until 2 more days
0
 
jhanceCommented:
BTW, please feel free to ask for explanation on any of this....

Here's an examples of code that establishes a connection.  Everything is pretty straightforward except for the:

(LPVOID)::RasCallBack in the call to RasDial().  This is a callback function used to receive status updates from the connection.


DWORD Dial()
{
      RASDIALPARAMS mDialParams;
      hRasConn = NULL;

      mDialParams.dwSize = sizeof(RASDIALPARAMS);
      _tcscpy(mDialParams.szEntryName, lpszEntryName);
      _tcscpy(mDialParams.szPhoneNumber, _T(""));
      _tcscpy(mDialParams.szCallbackNumber, _T(""));
      _tcscpy(mDialParams.szUserName, lpszLogonUser);
      _tcscpy(mDialParams.szPassword, lpszLogonPw);
      _tcscpy(mDialParams.szDomain, _T(""));


      DWORD dwStatus = ::RasDial(NULL, NULL, &mDialParams, 1, (LPVOID)::RasCallBack, &hRasConn);

      return dwStatus;
}

Here's an example of a callback function that sends a message to the apps window:

void WINAPI RasCallBack(HRASCONN hRasConn, UINT unMsg, RASCONNSTATE rascs, DWORD dwError, DWORD dwExtendedError)
{
      rasconnCurrentState = rascs;

      UINT WM_RASCHANGE = ::RegisterWindowMessage(_T("RasChangeState"));

      if(::pCwndParent != NULL){
            ::PostMessage(::pCwndParent->m_hWnd, WM_RASCHANGE, (WPARAM)dwError, (LPARAM)rascs);
      }
}


To hang up:

BOOL HangUp()
{
      if(GetState() != RASCS_Disconnected){
            if(hRasConn != NULL){
                  RasHangUp(hRasConn);
            }
      }

      return TRUE;
}

When debugging a dialer it's often the case that you'll leave the line open and you won't be able to run it again.  The following function looks for ANY open RAS session and hangs it up:

void CloseAllConnections()
{
      HRASCONN hrc;

      DWORD dwBufSize, dwNumConnections;

      LPRASCONN plpRasConn;
      plpRasConn = new RASCONN[32];

      plpRasConn[0].dwSize = sizeof(RASCONN);
      dwBufSize = 32 * sizeof(RASCONN);

      if(RasEnumConnections(plpRasConn, &dwBufSize, &dwNumConnections) != 0){
            AfxMessageBox("ERROR", MB_OK);
      }

      for(DWORD i=0; i<dwNumConnections; i++){
            hrc = plpRasConn[i].hrasconn;
            RasHangUp(hrc);
            ::Sleep(1000);
      }

      delete [] plpRasConn;
}
0
 
hiap_hoAuthor Commented:
What API library are you using ?
can you give me a more complete code ?
can I specify the phone number of the ISP to use ?
0
 
hiap_hoAuthor Commented:
What API library are you using ?
can you give me a more complete code ?
can I specify the phone number of the ISP to use ?
0
 
hiap_hoAuthor Commented:
Do I need to load any library ?
0
 
jhanceCommented:
What API library are you using ?

Add RASAPI32.LIB to your LINK setup.  This is the import library for RASAPI32.DLL.

can you give me a more complete code ?

What part are you having trouble with?  I'll be happy to explain.  I can see if I can whip up an example...


can I specify the phone number of the ISP to use ?

No, you must build a PHONEBOOK entry.  Usually you do this via the "Make new Connection" icon in the Dial-Up Networking Folder or RAS Control Panel.
0
 
hiap_hoAuthor Commented:
Do you have any contacts ? email ? or anything so that I can send you the complete code including the workspace ?
I have built the application, and everything works out correctly.
The sequence of message gotten is  :
 Open Port
 Port Opened
 Connecting Device
( modem is dialing )
 Device Connected
 All Device Connected
 Start to Authenticate
 Authenticate
(idle )
 Disconnected
( the error message is the username and password is invalid in the domain )
However, using a similar program I can get it worked in Pascal ( Delphi )
Can you tell me what is possibly wrong ?


0
 
jhanceCommented:
Please download and review:

http://www.jwhance.com/RasDialTest.zip

It's a small project that dials a RAS/DUN connection.

0
 
hiap_hoAuthor Commented:
I have understand why my program won't work. It's because I tried to type in the connection entry. Is that anyway that I can type in the connection entry manually without retrieving it from the Phonebook and it's still work ?  Moreover the RasDial() function actually stated if we never put in szEntryName field we can actually stated the Phone number, but it does not seems to work. Can you give me more explanation on this ? Thanks a lot. You have been really helpful.
0
 
hiap_hoAuthor Commented:
I have understand why my program won't work. It's because I tried to type in the connection entry. Is that anyway that I can type in the connection entry manually without retrieving it from the Phonebook and it's still work ?  Moreover the RasDial() function actually stated if we never put in szEntryName field we can actually stated the Phone number, but it does not seems to work. Can you give me more explanation on this ? Thanks a lot. You have been really helpful.
0
 
hiap_hoAuthor Commented:
I have understand why my program won't work. It's because I tried to type in the connection entry. Is that anyway that I can type in the connection entry manually without retrieving it from the Phonebook and it's still work ?  Moreover the RasDial() function actually stated if we never put in szEntryName field we can actually stated the Phone number, but it does not seems to work. Can you give me more explanation on this ? Thanks a lot. You have been really helpful.
0
 
jhanceCommented:
I too have found that the direct phone number entry to RasDial() doesn't work.  I cannot explain it.

You can simulate dialing an arbitrary number by using the RasCreatePhonebookEntry().  Just build a phonebook entry with the number you need to dial, dial it, and then delete the entry when you are done.  I've done this before and it works.
0
 
hiap_hoAuthor Commented:
OK, can you explain why typing in the szEntryName won't work also ?
0
 
jhanceCommented:
szEntryName _DOES_ work.  Did you look at my example?  It's get the szEntryName from the choice you make in the dropdown box from the list of available phonebook connections.

I don't suggest typing it in, however, as the name must match exactly.  It's too easy to make a typing mistake.  That's why I used the combo box to select the connection.
0
 
hiap_hoAuthor Commented:
I know and I'm aware about it. It's working with the combo box, but when you supply it from an edit box, I won't work
the sequence will go as what I told you before. Everything will be set and finally disconnected
0
 
hiap_hoAuthor Commented:
If you change the combobox setting to the one that doesn't recieved any typing entry, the same effect will occur too, and I still could not find any reasons why
0
 
jhanceCommented:
Let me try it and I'll let you know what happens...
0
 
jhanceCommented:
I changed the code in the OnOK() function to start like this and added an editbox to the dialog called IDC_MANUAL.  If there is any text in the box, it will use that as input to the szEntryName instead of the text from the combo box.  Works perfectly as long as you type in the correct string.  Otherwise RasDial() fails with an invalid connection error.


void CRasDialTestDlg::OnOK()
{
      // Get the entry to dial and dial it
      TCHAR lpszEntry[256];

      // First see if IDC_MANUAL has a value, if so, use it instead of the combo box
      GetDlgItemText(IDC_MANUAL, lpszEntry, 255);
      if(_tcslen(lpszEntry) <= 0){
            GetDlgItemText(IDC_CONNECTION, lpszEntry, 255);
      }
0
 
hiap_hoAuthor Commented:
OK, Thanks, I'll try it again and let you know of the progress.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 15
  • 9
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now