Solved

RAS problem

Posted on 2000-03-24
4
324 Views
Last Modified: 2013-12-03
I'm having a problem to establish a dial-up connection while using this code. The state goes 'opening port', 'port opened', 'connecting device', 'disconnecting', with error=630 'closing due to hardware failure'. When I just click on the connection, it connects normaly. The code is located in a dll, just in case it's relevant.

---------------------------
#include "general.h"
#include <ras.h>
CDataQueue NotifyQueue;
HRASCONN connection=0;
char szdunLastError[256];


//Executed in the main thread
void
dunNotifyAll(LONG notifycode)
{
      while(!NotifyQueue.IsEmpty())
      {
            LONG address=0;
            NotifyQueue.Get(&address, 4);
            CDUNNotify *nt=(CDUNNotify*)address;
            if(nt!=NULL) nt->NotifyDUN(notifycode);
      }
}

//Callback function for RASDial.
void
dunNotifyStateChanged(UINT uMsg, RASCONNSTATE state, DWORD dwError)
{
      
      //Store error string so it can be later retrieved by dunGetError()
      if(dwError)
      {
            RASCONNSTATUS status;
            status.dwSize = sizeof(status);
            RasGetConnectStatus(connection, &status);
            
            RasGetErrorString(dwError, szdunLastError, sizeof(szdunLastError));
            RasHangUp(connection);
            
            //Notify all that an error has occured. Extened error information can be retrieved with dunGetError()
            dunNotifyAll(ERR_GENERAL);
            return;
      }

      //If connection established succesfully
      if(state==RASCS_Connected)
      {
            dunNotifyAll(ERR_SUCCESS);
      }
}


//Asynchronically starts a connection
void
dunConnect(CDUNNotify *object)
{
      //Get dial-up entry value
      CString strDUN=iniGet("DUNEntry", "LAN");
      
      //If it's 'LAN', no need to connect, notify right away, and exit
      if(strDUN=="LAN")
      {
            object->NotifyDUN(ERR_SUCCESS);
            return;
      }
      
      //Add notification client
      LONG address = (LONG)object;
      NotifyQueue.Append(&address, 4);

      //If there are no ongoing dialup, this is the only request from this dll
      if(NotifyQueue.GetSize()==4)
      {
            //dial
            RASDIALPARAMS params;
            CLEAN(&params);
            params.dwSize = sizeof(RASDIALPARAMS);
            strcpy(params.szEntryName, strDUN);
            int nResult = RasDial(NULL, NULL, &params, 0, &dunNotifyStateChanged, &connection);
            
            //If error occured, callback won't be called, so call it right away
            if(nResult!=0) dunNotifyStateChanged(0, (RASCONNSTATE)0, nResult);
      }
}


//Disconnect
void
dunDisconnect()
{
      RasHangUp(connection);
}


//Terminates the connection in case it was established by the application
void
dunCleanUp()
{
      if(connection!=0) dunDisconnect();
}


void
dunGetError(char *buf)
{
      strcpy(buf, szdunLastError);      
}
0
Comment
Question by:MikeP090797
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Author Comment

by:MikeP090797
ID: 2654793
Adjusted points from 300 to 500
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2655334
Callback functions must be defined as WINAPI:



void WINAPI dunNotifyStateChanged(...
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 500 total points
ID: 2655450
You have to:
1) Declare the callback function as WINAPI:  

void WINAPI dunNotifyStateChanged(...

2) Probably, provide the user name/password.

In other respects, your code works fine.
The test program is below.

The problem can be also in NotifyQueue and dunNotifyAll().
Try to comment these lines out.


#include <windows.h>
#include <ras.h>
#include <iostream.h>
#include <conio.h>

//CDataQueue NotifyQueue;

HRASCONN connection=0;
char szdunLastError[256];


//Callback function for RASDial.
void WINAPI
dunNotifyStateChanged(UINT uMsg, RASCONNSTATE state, DWORD dwError)
{

   //Store error string so it can be later retrieved by dunGetError()
   if(dwError) {
      RASCONNSTATUS status;
      status.dwSize = sizeof(status);
      RasGetConnectStatus(connection, &status);

      RasGetErrorString(dwError, szdunLastError, sizeof(szdunLastError));
      RasHangUp(connection);
      cout<<"Callback: ERROR "<<dwError<<endl;
      return;
   }

   cout<<state<<endl;

   //If connection established succesfully
   if(state==RASCS_Connected)
   {
      cout<<"Callback: CONNECTED"<<endl;
   }

}


//Asynchronically starts a connection
void
dunConnect()
{

   RASDIALPARAMS params;
   memset(&params,0,sizeof(params));
   params.dwSize = sizeof(RASDIALPARAMS);
   strcpy(params.szEntryName,"User");
   strcpy(params.szUserName,"Password");
   strcpy(params.szPassword,"HaTf432");
   DWORD nResult = RasDial(NULL, NULL, &params, 0,
      &dunNotifyStateChanged, &connection);
   
   if(nResult) cout<<"Unable to dial"<<endl;
}


//Disconnect
void
dunDisconnect()
{
RasHangUp(connection);
}


void main(void) {
   dunConnect();
   _getch();
   dunDisconnect() ;
}


0
 
LVL 8

Author Comment

by:MikeP090797
ID: 2656425
Great!! It works now.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question