CRasMonitor
v1.60
Welcome to CRasMonitor, A freeware MFC
class to monitor RAS (aka Dial-Up Networking) connections.
Features
- Simple and clean C++ interface.
- The code works on both Windows 9x and NT 4 / 2000, XP, 2003 and Vista.
The RAS API itself is very OS dependent with some of its functions only available on
Windows NT 4 or later.
- 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 (by default) 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 Authors 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 be explicitly tested in this scenario.
- CRasMonitor requires that the latest version of Winsock and Dial-Up
Networking are installed on client machines. If you are running Windows 95 (or Win95 B aka OSR2), you will need to download and install
Dial-Up Networking v1.3 from Microsoft. All more recent versions of Windows includes this
required updates, so no additional downloads are
required.
Copyright
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
History
V1.0 (5 July 1998)
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 optimisation added to reduce memory usage (c. 3 MB) on NT when
RAS service is not running. Thanks to Daniel Harth for this very neat optimisation.
- 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 customisation
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 occuring 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 authors 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)
- Update 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.
v1.42 (8 May 2000)
- Fixed a problem on NT where the PDH counters were being freed
prior to the being added to the m_Connections array.
- Also now allows the PDH counter names to be customized via an advanced registry value.
Thanks to Toni Zeitler for finding and help fix these two problems
v1.43 (30 April 2001)
- Updated copyright messages.
- Fixed a problem where the code would not run correctly on Win 9x.
- Connection speed for a connection is now reported on via a call to
TAPI just like the way the SDK sample RasBaud operates.
- Provision of the following defines which allow fine grained control
over what API's RasMonitor pulls in:
RAS_MONITOR_NO_DYNDATA
RAS_MONITOR_NO_PDH
RAS_MONITOR_NO_TAPI
v1.5 (19 December 2001)
- Code now tries to use RasGetConnectionDetails in preference to any
of the other methods. This new API is available from Windows 2000 onwards.
- Moved typedefs into namespace of class to avoid polluting the global
namespace
- Made all static data and methods non-static. This makes the code more
multi-thread safe in addition to the code being cleaner.
- Reworked how the NT Performance names can be tweaked by client apps
- Reviewed all the TRACE statements to ensure they were comprehensive
and accurate.
- Optimized checking of the Ras service state when running on NT.
- Removed need to keep an outstanding handle on the SCM throughout
the lifetime of the code when running on NT.
v1.51 (16 July 2003)
- Now gets Caller ID number, Caller ID name, Called ID
Number, Called Name, Connected ID number, Connected ID Name, Displayable
Address, Called Party and comment fields from TAPI for each call.
v1.60 (2 February 2007)
- Updated copyright details
- Updated the code to clean compile on VC 2005.
- Replaced all calls to ZeroMemory with memset.
- Code now uses new C++ style casts rather than old style C casts where
necessary.
- Optimized CRasMonitor constructor code
- Addition of a CRASMONITOR_EXT_CLASS and macro which makes the class
easier to use in an extension dll.
- TAPI line is now opened with LINECALLPRIVILEGE_MONITOR in
CRasMonitor::GetRasTAPIDetails method.
- Updated the documentation to use the same style as the web site.
API
Reference
The API consists of the class CRasConnection and the public member
functions of the class CRasMonitor
CRasConnection::m_sName
CRasConnection::m_sDeviceType
CRasConnection::m_sDeviceName
CRasConnection::m_ConnectionTime
CRasConnection::m_DialTime
CRasConnection::m_bConnected
CRasConnection::m_ConnectDuration
CRasConnection::m_DialDuration
CRasConnection::m_HangupTime
CRasConnection::m_dwConnectionSpeed
CRasConnection::m_dwBytesSent
CRasConnection::m_dwBytesReceived
CRasMonitor::Start
CRasMonitor::Stop
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 dialled. 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 current active
CRasConnection's. If 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 dialled.
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 being 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 the an array of the newly active connections. The
implementation in CRasMonitor does 2 things.
- Iterate through all the previously active connections which has now
disappeared and call the virtual OnDisconnect function for that connection.
- 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
- If you have any other suggested
improvements, please let me know so that I can incorporate them into the next release.
Contacting the Author
PJ Naughter
Email: pjna@naughter.com
Web: http://www.naughter.com
2 February 2007