CNamedPipe v1.17 A C++ class to encapsulate
Named Pipes
The class encapsulates the Named Pipe Inter Process Communication
mechanism as provided in Win32.
The class provides a thin veneer of the SDK API meaning that all the richness
the SDK provides is available through the class. The class also provides auto cleanup
and is UNICODE enabled with build configurations provided.
The enclosed zip file contains the CNamedPipe
source code and also includes a VC 2017 solution to build a small demonstration
app.
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.17 (20 March 2022)
- Updated copyright details.
- Updated the code to use C++ uniform initialization for all variable
declarations.
v1.16 (4 May 2020)
- Fixed various Clang-Tidy static code analysis warnings in the code.
v1.15 (14 March 2020)
- Updated copyright details.
- Fixed more Clang-Tidy static code analysis warnings in the code.
v1.14 (2 June 2019)
- Updated copyright details.
- Updated the code to clean compile on VC 2019
v1.13 (26 August 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.12 (19 December 2017)
- Updated copyright details
- Replaced CString::operator LPC*STR() calls throughout the codebase with
CString::GetString calls
- Replaced NULL throughout the codebase with nullptr. This means that the
minimum requirement for the framework is now VC 2010.
- GetNamedPipeClientProcessId, GetNamedPipeClientSessionId,
GetNamedPipeServerProcessId & GetNamedPipeServerSessionId API functions are
now called directly rather than through GetProcAddress.
- Verified there has been no further additions to Named Pipes from the
latest Windows 10 SDK
1 May 2017
- Updated the demo app to compile cleanly using /permissive-.
26 December 2015
- Verified there were no further changes to the Named Pipe API from the Windows
10 SDK.
- Verified the code compiles cleanly on VC 2015.
v1.11 (1 June 2015)
- Updated copyright details.
- Updated the sample app project settings to more modern default values.
- Reworked the class to make it a header only implementation.
- Added SAL annotations to all the code
- Removed the static Call method as it did not provide any C++ encapsulation
of the underlying API call
- Reworked the class to not be exception based. Now the class merely wraps
the underlying API calls in a RAII fashion.
- Removed the static ServerAvailable method as it did not provide any C++
encapsulation of the underlying API call.
- Updated the code to compile without taking a dependency on MFC.
- The methods which call WriteFileEx have been renamed to WriteEx.
- The methods which call ReadFileEx have been renamed to ReadEx.
- The ConnectClient method has been renamed to Connect.
- The DisconnectClient method has been renamed to Disconnect.
- Added support for GetNamedPipeComputerName, GetNamedPipeClientProcessId,
GetNamedPipeClientSessionId, GetNamedPipeServerProcessId, GetNamedPipeServerSessionId &
ImpersonateNamedPipeClient APIs.
v1.10 (12 July 2008)
- Updated copyright details.
- Updated sample app to clean compile on VC 2008
- The code has now been updated to support VC 2005 or later only.
- Code now compiles cleanly using Code Analysis (/analyze)
- Removed the m_bAutoClose member variable and concept from class
v1.09 (30 November 2007)
- Updated the sample apps to clean compile on VC 2008
v1.08 (29 November 2007)
- Updated copyright details.
- Updated the sample apps to clean compile on VC 2005
- Sample client app now defaults to "." (meaning the current machine)
as the server to connect to.
- CNamedPipeException::GetErrorMessage now uses the FORMAT_MESSAGE_IGNORE_INSERTS
flag. For more information please see Raymond Chen's blog at
http://blogs.msdn.com/oldnewthing/archive/2007/11/28/6564257.aspx. Thanks
to Alexey Kuznetsov for reporting this issue.
- CAppSettingsException::GetErrorMessage now uses Checked::tcsncpy_s if compiled
using VC 2005 or later.
- Provision of new overloaded versions of the Peek, Write and Read methods
which allows the dwBytesRead/dwBytesWritten parameters to be returned as an
output parameter as opposed to the return value of the method. This helps resolve
a situation where the underlying WriteFile / ReadFile call fails but some data
has actually been written / read from the pipe. Thanks to Gintautas Kisonas
for reporting this issue.
- dwBytesRead, dwTotalBytesAvail and dwBytesLeftThisMessage parameters to
Peek are now pointers rather than references. Thanks to Gintautas Kisonas for
reporting this issue.
v1.07 (15 July 2006)
- Updated copyright details.
- Renamed AfxThrowNamedPipeException to ThrowNamedPipeException and made it
part of the CNamedPipe class.
- CNamedPipe is no longer derived from CObject as it was not really required.
- Optimized CNamedPipe constructor code.
- Code now uses new C++ style casts rather than old style C casts where necessary.
- Optimized CNamedPipeException constructor code
- Removed the unnecessary CNamedPipeException destructor
- Removed some unreferenced variables in the sample app.
- Updated the code to clean compile on VC 2005
- Updated documentation to use the same style as the web site.
- Addition of a CNAMEDPIPE_EXT_CLASS macro to allow the classes to be easily
added to an extension dll.
v1.06 (19 November 2003)
- Fixed ASSERT's at the start of most CNamedPipe functions which verify that
the pipe handle is valid. Thanks to Metrich Frederic for reporting this issue.
v1.05 (12 November 2003)
- Attach now includes an AutoClose parameter. This allows control over whether
the pipe handle should be closed when the pipe object goes out of scope or CNamedPipe::Close
is called. Thanks to Metrich Frederic for reporting this issue.
v1.04 (5 March 2003)
- Changed the class to use exceptions rather than SDK style return values.
v1.03 (9 November 2002)
- ConnectClient now returns TRUE if the last error returns ERROR_PIPE_CONNECTED
which indicates that a client is already connected before we make the call.
Thanks to Metrich Frederic for reporting this.
v1.02 (28 July 2002)
- Updated sample server app to do Flush of the pipe before we disconnect the
client. Thanks to "Martin" for spotting this problem.
v1.01 (21 February 2002)
- Updated copyright message in source code and documentation
- Fixed a bug in Close method where the handle value was not being reset to
INVALID_HANDLE_VALUE.
- Tidied up the TRACE code
- Tidied up build configurations for sample apps
v1.0 (3 August 1998)