These 2 classes provides a clean C++ interface to the Win32 IPC mechanism called
mailslots. They are very similar to the more common "Named pipe" IPC mechanism.
Unlike named pipes, mailslots use datagrams. A datagram is a small packet of information
that the network sends along the wire. Like a radio or television broadcast, a datagram
offers no confirmation of receipt; there is no way to guarantee that a datagram
has been received.
Mailslots can broadcast messages within a domain. If several processes in a domain
each create a mailslot using the same name, every message that is addressed to that
mailslot and sent to the domain is received by the participating processes. Because
one process can control both a server and client mailslot handle, applications can
easily implement a simple message-passing facility within a domain.
The enclosed zip file contains the source
code for the 2 classes and also includes a VC 2017 solution to build a demonstration
program called WinNotify. It is based on the old MS WinPopup utility as shown below:
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.
Updates
v1.24 (9 April 2022)
- Updated copyright details.
- Updated the code to use C++ uniform initialization for all
variable declarations.
v1.23 (3 May 2020)
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.22 (26 December 2019)
- Fixed various Clang-Tidy static code analysis warnings in the code.
- Replaced BOOL with bool throughout the code.
v1.21 (21 September 2019)
- Fixed a number of compiler warnings when the code is compiled with VS
2019 Preview
v1.20 (3 June 2019)
- Updated copyright details
- Updated the code to clean compile on VC 2019
v1.19 (14 October 2018)
- Updated copyright details.
- Fixed a number of C++ core guidelines compiler warnings. These changes
mean that the code will now only compile on VC 2017 or later.
v1.18 (30 April 2017)
- Updated copyright details.
- Updated the code to compile cleanly using /permissive-.
v1.17 (16 January 2016)
- Updated copyright details.
- Verified the code compiles cleanly in VC 2015
v1.16 (10 May 2015)
- Updated copyright details.
- Updated the project settings to more modern defaults
- Removed all unnecessary TRACE calls
- Made the classes into a header only implementation
- Updated the code to clean compile on VC 2013
- Reworked the CServerMailslot::Open and CClientMailslot::Open to provide
the full mailslot name as its first parameter. This allows the class to avoid
the use of CString
- Addition of a CServerMailslot::GetInfo method which encapsulates GetMailslotInfo.
- Removed the CServerMailslot::MessageWaiting, MessageCount, SizeOfWaitingMessage,
MaximumMessageSize, GetCreationTime, GetLastAccessTime & GetLastWriteTime
methods
- Added SAL annotations to all the code
- Reworked the CServerMailslot::Read method to use a pointer for returning
the number of bytes read
- Reworked the CClientMailslot::Write method to use a pointer for returning
the number of bytes write
- Replaced all ASSERT calls with ATLASSERT. This means that the class can
now be used without the need to pull in MFC
v1.15 (7 September 2008)
- Updated copyright details.
- Code now compiles cleanly using Code Analysis (/analyze)
- Updated code to compile correctly using _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
define
- Updated sample app to clean compile on VC 2008
- The code has now been updated to support VC 2005 or later only.
- Removed VC 6 style AppWizard comments from the code.
- Updated the sample app to improve on the error reporting.
v1.14 (8 September 2007)
- Updated copyright details.
- Minor code tidy up.
v1.13 (23 December 2006)
- Code now uses CString instead of raw TCHAR buffers in various functions
- Classes now do not derive from CObject as it was not really required
v1.12 (22 December 2006)
- Updated copyright details
- Updated the documentation to use the same style as the web site
- Optimized CServerMailslot constructor code
- Addition of a CMAILSLOT_EXT_CLASS preprocessor macro to allow the classes
to be more easily added to an extension dll
- Reviewed all TRACE statements for correctness
- Optimized CClientMailslot constructor code
- Updated the code to clean compile on VC 2005
- Code now uses newer C++ style casts instead of C style casts.
- Changed the default size of the formview window in the sample ap to avoid
scroll bars using default fonts.
v1.11 (26 July 2003)
- Updated copyright details.
- Fixed issue in CClientMailslot::Open which was causing it to only allow
one instance of the mailslot to be opened. Thanks to GdP Software for reporting
this problem.
11 August 1998
- Inclusion of a VC 5 make file.
- Tidy up of the resources the program uses plus their names.
v1.11 (10 August 1998)
- Fixed a bug in the Close function of both classes where the mailslot handle
was not being set back to INVALID_HANDLE_VALUE.
v1.1 (26 July 1998)
- Provision of Unicode build configurations
- Fixed a bug in CClientMailslot destructor
- CServerMailslot::Close() & CClientMailslot::Close() now work correctly
when the mailslot is already closed
- Fixed a level 4 warning in the CWinNotifyDoc in the demo program.
- Complete documentation for the classes is now provided in the form of a
HTML file
- Changed 2 functions which used a pointer parameter to now use a C++ reference
instead.