Click here to Skip to main content
Click here to Skip to main content

CRasMonitor v1.41

, 9 Mar 2000
Rate this:
Please Sign up or sign in to vote.
A shareware application to monitor your Dial-Up Networking Connections.

CRasMonitor

Welcome to CRasMonitor v1.41, a freeware MFC class to monitor RAS (a.k.a. Dial-Up Networking) connections. This class forms the basis of the code for RasMan. It uses window messages to notify client code of various RAS events. These include notification of connections being made and closed.

Features
Usage
History
API Reference
Planned Enhancements
Contacting the Author

Features

  • Simple and clean C++ interface.
  • The code works on both Windows 95/98 and NT. The RAS API itself is very OS dependent with some of its functions only available on Windows NT.
  • The code has been designed in such a way that it has a minimum impact on the performance of the OS.
  • The classes are fully Unicode compliant.

Usage

  • To use the class in your code, simply include rasmonitor.cpp in your project and #include rasmonitor.h in which ever of your modules needs to make calls to the class. As of v1.4 the code depends on 2 additional modules of the author. These are the DynData which encapsulate the Windows 95/98 performance counters and CPdh which encapsulates the NT Performance Counters. You will need to download both of these modules from the Author's web site to use the CRasMonitor class. Also ensure that these modules have been added to your project.
  • Your code will need to include MFC either statically or dynamically.
  • You will also need to have afxtempl.h, winsock.h or afxsock.h, afxpriv.h and winsvc.h in your precompiled header. The code will work just as well in a GUI or console app. The code should also work in a multithreaded application, although it has not been explicitly tested in this scenario.
  • CRasMonitor requires that the latest version of Winsock and Dial-Up Networking are installed on client machines. Even if you are running the latest version of Windows 95 (Win95 B a.k.a. OSR2), you will still need to download and install this update. Windows 98 includes the latest versions, so no additional downloads are required.

    The easiest way to determine if you have the correct version of Dial-Up Networking installed is to check the icon that is added to your system tray (next to the clock) when you establish a connection to your Internet Service Provider (ISP), as shown below:

     or  You need to download the updates
    You already have Dial-Up Networking v1.3 or above installed.

    The updated versions are available from the Microsoft web site. At the time or writing, you can get the update by clicking here. If that page has moved (which it has in the past), you can find the update by following these steps:

    • Go to the Microsoft site.
    • Follow the links to Products, Windows, Windows 95, System updates.
    • Download the Dial-Up Networking v1.3 update

    For NT users, you need to ensure that you have the PSAPI.DLL installed into your system32 directory on NT. If this file is not already present on your machine, then you can download it from here.

History

  • V1.0 (5 July 1998)
    • Initial public release.
  • 26 July 1998
    • RasMan sample application had been updated. See the rasman.htm file for further details.
  • v1.1 (1 October 1998)
    • Updated code to include a virtual OnDial method
    • Optimized the code by using CArray::ElementAt
    • Added the following member variables to CRasConnection: Dial Time, whether or not the connection is currently connected, Dial Duration and the RAS handle
    • Renamed the connection variable of CRasConnection
    • Updated the sample program to v1.1
    • Updated the version info in the sample app to include the build date
    • Fixed a problem when enumerating more than one RAS connection at a time.
    • Sample app now uses LoadImage instead of LoadIcon to avoid the shell first scaling up to 32*32 and then back to 16*16.
    • What this means is that the icons RasMan puts in the tray notification area will not look blurred.
    • Fixed a memory leak in CRasMonitor::DoCheck() when multiple connections were being enumerated.
    • Included a new selection of tray icons in the sample app.
    • Updated the documentation to reflect the name changes and the new member variables and methods
    • Added a popup menu item to bring up the help file.
  • v1.2 (6 November 1998)
    • Major optimization added to reduce memory usage (c. 3 MB) on NT when RAS service is not running. Thanks to Daniel Harth for this very neat optimization.
    • Internally, the code now uses a hidden window to perform the monitoring instead of a worker thread. This helps avoid potential deadlock problems which can occur as previously the code used a worker thread.
    • Now uses window messages instead of virtual functions to implement class customization
  • 17 November 1998
    • Removed sample app as RasMan application is now shareware. All that is now included is the source code, header file and associated documentation.
  • v1.21 (2 February 1999)
    • Fixed a compile problem which was occurring when code was compiled for UNICODE.
    • Fixed a crash which was occurring when the code was run on NT and you do not have RAS installed.
    • When running on NT, the code now only uses SC_MANAGER_ENUMERATE_SERVICE privileges when connecting to the Service Configuration Manager.
    • CRasConnection connection now includes a standard MFC Serialize method.
    • CRasMonitor now has a standard MFC Serialize method. This can be incorporated into an app to prevent RAS events being lost if the application or OS were to crash. This is used in the author's RasMan application to ensure no RAS records were lost even if the machine crashed while any RAS connection was in progress.
  • v1.4 (21 February 1999)
    • Synced version number up to the same version as RasMan application.
    • Now reports the following additional statistics: Connection speed (Bytes / Second) (on Windows 95, 98 only), Bytes sent (Windows 95, 98 & NT) and Bytes received (Windows 95, 98 & NT)
    • Updated the usage instructions about what is required on client machines.
  • v1.41 (25 January 2000)
    • Removed a memory leak which was occurring on NT where the CPdhCounter instances in the GetInitialConnectionDetails and GetCurrentConnectionDetails functions were not being tidied up. This has been accomplished by restructuring the code to create and add the counters to the performance once of in the CRasConnection constructors.
    • Removed reference to source code of RasMan app which is now not available.

API Reference

The API consists of the class CRasConnection and the public member functions of the class CRasMonitor.

CRasConnection::m_sName

Remarks

A string that specifies the phone-book entry used to establish the remote access connection. If the connection was established using an empty entry name, this string consists of a “.” followed by the connection phone number.

CRasConnection::m_sDeviceType

Remarks

A string that specifies the type of the current device, if available. For example, common device types supported by RAS are “modem”, “pad”, “switch”, “isdn”, or “null”.

CRasConnection::m_sDeviceName

Remarks

A string that specifies the name of the current device, if available. This would be the name of the modem, for example, “Hayes Smartmodem 2400”; the name of the PAD, for example “US Sprint”; or the name of a switch device, for example “Racal-Guardata”.

CRasConnection::m_ConnectionTime

Remarks

A SYSTEMTIME representation of when this connection was made/connected. The time stored is Local and not UCT.

CRasConnection::m_DialTime

Remarks

A SYSTEMTIME representation of when this connection was dialed / attempted. The time stored is Local and not UCT. The dial time will always be more historic than the connection, for any connection.

CRasConnection::m_ConnectDuration

Remarks

The number of seconds for which this connection was active.

CRasConnection::m_DialDuration

Remarks

The number of seconds taken to make the connection for which this RAS connection.

CRasConnection::m_HangupTime

Remarks

A SYSTEMTIME representation of when this connection was closed. The time stored is Local and not UCT.

CRasConnection::m_dwConnectionSpeed

Remarks

The connection speed in bits per second for this connection. Please note that this value is always reported as 0 on NT as currently there is no documented way of retrieving this value on NT.  Another point to bear in mind is that on 95/98, this is the accumulated connection speed of all current RAS connections. This means that if you are using multilink features or have two separate RAS connections active at the one time, then this value will be the total of both connections.

CRasConnection::m_dwBytesSent

Remarks

The total number of bytes transmitted by this connection. Please note that this value is a total for all RAS connections similar to the Connection Speed above.

CRasConnection::m_dwBytesReceived

Remarks

The total number of bytes received by this connection. Please note that this value is a total for all RAS connections similar to the Connection Speed above.

CRasMonitor::Start

BOOL CRasMonitor::Start(CWnd* pNotifyWnd, UINT nNotifyMessage);

Return Value

TRUE if monitoring of RAS connections has started, otherwise FALSE.

Parameters

  • pNotifyWnd Window to send notification messages to
  • nNotifyMessage the window message to use for notification messages

Remarks

Starts monitoring of active RAS connections. If the call fails, you should use GetLastError to determine the reason. When certain RAS related events occur, the class will send a nNotifyMessage to pNotifyWnd. The meaning of WPARAM and LPARAM are as follows:

WPARAM LPARAM Meaning
RAS_DIAL_EVENT Contains a pointer to the CRasConnection instance which has just dialed. Its type is CRasConnection* Called when a RAS connection is initially dialed
RAS_CONNECT_EVENT Contains a pointer to the CRasConnection instance which has just connected. Its type is CRasConnection* Called when a RAS connection has just connected
RAS_DISCONNECT_EVENT Contains a pointer to the CRasConnection instance which has just disconnected. Its type is CRasConnection* Called when a RAS connection disconnects
RAS_CHECK_EVENT Contains a pointer to the array of currently active CRasConnections. Its type is CArray<CRasConnection, CRasConnection&>* Called periodically with the current RAS connections

See Also

CRasMonitor::Stop

CRasMonitor::Stop

BOOL CRasMonitor::Stop();

Return Value

TRUE if monitoring of RAS connections has stopped, otherwise FALSE.

Parameters

None

Remarks

Stops monitoring of active RAS connections. If the call fails, you should use GetLastError to determine the reason.

See Also

CRasMonitor::Start

CRasMonitor::OnDial

virtual void CRasMonitor::OnDial(const CRasConnection& connection);

Return Value

None

Parameters

  • connection A class representation of the RAS connection which has just been dialed.

Remarks

Derived classes are responsible for implementing their own version of OnConnect.

See Also

CRasMonitor::OnConnect

CRasMonitor::OnConnect

virtual void CRasMonitor::OnConnect(const CRasConnection& connection);

Return Value

None

Parameters

  • connection A class representation of the RAS connection which has just become active.

Remarks

Derived classes are responsible for implementing their own version of OnConnect.

See Also

CRasMonitor::OnDisconnect

CRasMonitor::OnDisconnect

virtual void CRasMonitor::OnDisconnect(const CRasConnection& connection);

Return Value

None

Parameters

  • connection A class representation of the RAS connection which has just been closed.

Remarks

Derived classes are responsible for implementing their own version of OnDisconnect. If you look at the sample app "RasMan", you will see that it does a SendMessage to the mainfrm window.

See Also

CRasMonitor::OnConnect

CRasMonitor::OnCheck

virtual void CRasMonitor::OnCheck(RASCONN* pConnections, DWORD dwConnections);

Return Value

None

Parameters

  • pConnections pointer to an array of the currently active connections. The structure used is the same as that used by native SDK RAS calls.
  • dwConnections The number of elements in pConnections.

Remarks

This function is called every second internally by CRasMonitor. The parameters it is called with include an array of the newly active connections. The implementation in CRasMonitor does 2 things:

  1. Iterates through all the previously active connections which has now disappeared and calls the virtual OnDisconnect function for that connection.
  2. For any new connections which have appeared, call the virtual OnConnect for that connection and add it to the internal array of active connections.

Planned Enhancements

  • Package the code up into an OCX to allow non MFC apps to use the code.
  • If you have any other suggested improvements, please let me know so that I can incorporate them into the next release.

Contacting the Author

Please send any comments or bug reports to me via email. For any updates to this article, check my site here.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

PJ Naughter

United States United States
No Biography provided

Comments and Discussions

 
QuestionProgrmatically Creating New Modem PinmemberRangaraman12-Jul-12 4:37 
GeneralAlternate way to monitor RAS connection status/information via GUI automation Pinmemberdaluu17-Oct-07 14:01 
QuestionBeginner requesting help and more documentation on how to make use of this MFC class Pinmemberdaluu17-Oct-07 8:55 
Generalincoming calls PinmemberDlt7513-Dec-05 22:35 
Generalkhj PinsussAnonymous5-Feb-05 23:00 
QuestionHow to invoke dialup property in 98 Pinmembervijay_visana4-Aug-04 20:36 
QuestionHow to monitor in and out bandwidth of a single APP Pinmembertyounsi5-May-04 0:41 
Generalcapturing ras errors PinmemberParas6-Aug-03 15:16 
Generaltelephone number Pinmemberbalu_pl14-Jun-03 14:00 
How to get telephone number using Your class?Confused | :confused:
GeneralRe: telephone number Pinmemberpjnaughter15-Jun-03 2:05 
Generalbig beginner problem ..... Pinsussbalu26-Jun-03 13:47 
GeneralRe: big beginner problem ..... Pinmemberpjnaughter7-Jun-03 0:01 
Generalbig thx ... Pinmemberbalu_pl7-Jun-03 1:25 
GeneralRe: big thx ... Pinmemberpjnaughter7-Jun-03 6:27 
GeneralRe: big thx ... Pinmemberbalu_pl11-Jun-03 13:38 
GeneralRe: big thx ... Pinmemberpjnaughter11-Jun-03 15:18 
Questionwhat the message window gets from com port? Pinsussshahid cheema25-Jul-02 1:45 
Generalsimple notification tool PinmemberJerome20-Mar-02 12:12 
GeneralRe: simple notification tool PinmemberAnonymous26-Mar-02 22:42 
GeneralRe: simple notification tool PinmemberDave Myers2-Apr-03 11:35 
GeneralRe: simple notification tool Pinmemberpjnaughter2-Apr-03 23:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 10 Mar 2000
Article Copyright 2000 by PJ Naughter
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid