We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Question on RasConnectionNotification

Till asked
Medium Priority
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:

  hConnEvent: THandle;

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

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?
Watch Question

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.


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.

But couldn't you see the code that how to get the currecnt connection and other functionalities?

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.


Hi all again,

  RASEnumConnections as you said , detects the connection immediately this is true. I think the missing part of yor code is the
 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,



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".


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



Yes, of course... but that was only an introduction to my actual question, regarding the invalid handle passed.
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.