Solved

Question on RasConnectionNotification

Posted on 1998-11-20
9
356 Views
Last Modified: 2009-12-16
I intend to write an application that detects when the user establishes an internet connection (the same thing as ICQ's agent does).
I tried to set a timer and do RasEnumConnections each second or so, but the problem is that RasEnumConnections detects the connection when dialing and not when it's established.
So I took a look at the win32api reference and found the function RasConnectionNotification. It lets you specify an event object and sets this event to signaled when it detects a connection. (I wonder how the ICQ agent did this since that function has not been available until Win98.)

Here's some sample code:

var
  hConnEvent: THandle;

function Foo: Longint;
begin
  hConnEvent := CreateEvent(nil, True, False, nil);
  Result := RasConnectionNotification(hConnEvent,    
    RASCN_Connection);
end;

My problem is as follows: The CreateEvent function doesn't cause any error (error code 0) and returns a handle. But the return value of RasConnectionNotification in the sample code is always 6, what means that the handle is invalid. What am I doing wrong?
0
Comment
Question by:Till
  • 3
  • 3
  • 3
9 Comments
 
LVL 4

Expert Comment

by:dwwang
ID: 1347439
Download the http://www.magsys.co.uk/delphi/rascomp.zip,
it's an improved version of TRas, in the sample included you can find what you need and more.

0
 

Author Comment

by:Till
ID: 1347440
Sorry Dwang,
but I made such wrapper components myself, and they work quite well. In the code you describe, the file "ras.h" translated is of a quite old version, and it does not even contain the function I needed information about.
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1347441
But couldn't you see the code that how to get the currecnt connection and other functionalities?
0
 

Expert Comment

by:msac_m
ID: 1347442
Hi Till,

  Today I wrote a program whose aim is the same as yours.
And I used RASEnumConnections, and RasGetConnectStatus
I did not encounter  your problem. After I connected to my ISP server then RasGetConnectStatus fell into the case RASCS_Connected which is true.

Regards.


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:msac_m
ID: 1347443
Hi all again,

  RASEnumConnections as you said , detects the connection immediately this is true. I think the missing part of yor code is the
RASGetConnectStatus.
 After you enumerate the Connections you will get how many connections available, this value is returned in the last variable of the enum function. After getting the number you must build a loop which checks the connections states. Whether connected or not.
The most importatnt two state are,
    RASCS_Connected = RASCS_DONE, // ESTABLISHED
     RASCS_Disconnected

Regards,

0
 

Author Comment

by:Till
ID: 1347444
Hmm... that was not exactly what I wanted... I think I'll close this question. I know how I can do the stuff with RasEnumConnections, but I think it's a little waste of system resources with that timer. Therefore I tried to get along with that other new function but it always returns "invalid handle".
0
 

Expert Comment

by:msac_m
ID: 1347445

Hi Till,

   When I read your question, I saw that you was mentioning that RasEnumConnections detects the connection immediately. In my answer I wanted to point out that this is not the case, In fact after the connection established it says that  RASCS_Connected

Regards,

0
 

Author Comment

by:Till
ID: 1347446
Yes, of course... but that was only an introduction to my actual question, regarding the invalid handle passed.
0
 
LVL 4

Accepted Solution

by:
dwwang earned 130 total points
ID: 1347447
Hi, the RasConnectionNotification API call is only available in WinNT, are you sure you are not using it in Win95/98?

If you are using Win95/98, you can only use RasEnumConnections.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now