Download source files - 8 Kb
Introduction
Welcome to CAnonymousPipe v1.0, A freeware MFC class to encapsulate the anonymous Pipe IPC
method as provided in Win32.
Features
- Simple and clean C++ interface.
- The classes are fully Unicode compliant and include Unicode built options in the
workspace file.
Usage
- To use the class in your code simply include apipe.cpp in your project and
#include apipe.h
in which ever of your modules needs to make calls to the class.
- Your code will need to include MFC either statically or dynamically.
History
v1.0 (3 August 1998)
API Reference
The API consists of the class CAnonymousPipe
and its public member functions:
CAnonymousPipe
~CAnonymousPipe
Create
Close
Write
Read
Peek
IsOpen
AssertValid
Dump
- CAnonymousPipe::CAnonymousPipe
- CAnonymousPipe();
Remarks:
Standard default constructor. Initialises the pipe handles to a default value.
See Also:
~CAnonymousPipe
- CAnonymousPipe::~CAnonymousPipe
- ~CAnonymousPipe();
Remarks:
Standard default destructor. Will close any pipe handles which are still open.
See Also:
CAnonymousPipe
- CAnonymousPipe::Create
- BOOL Create(LPSECURITY_ATTRIBUTES lpPipeAttributes = NULL, DWORD dwSize = 0);
Return Value:
Non-Zero if the anonymous pipe was successfully created otherwise FALSE. Use
GetLastError()
to get extended error information.
Parameters:
- lpSecurityAttributes -- Pointer to a
SECURITY_ATTRIBUTES
structure
that specifies a security descriptor for the new anonymous pipe and determines
whether child processes can inherit the returned handle. If
lpSecurityAttributes is NULL, the named pipe gets a default security
descriptor and the handle cannot be inherited.
- nSize -- Specifies the buffer size for the pipe. The size is only a suggestion;
the system uses the value to calculate an appropriate buffering mechanism. If this
parameter is zero, the system uses the default buffer size.
Remarks:
Creates an anonymous server side pipe. Unlike named pipes this function will work on non
NT platforms including Windows 95 and Windows 98.
- CAnonymousPipe::Close
- BOOL Close();
Return Value:
Non zero if the anonymous pipe was closed otherwise FALSE. Use
GetLastError()
to get extended error information.
Remarks:
Closes the pipe.
- CAnonymousPipe::Write
- BOOL Write(LPCVOID lpBuffer, DWORD dwNumberOfBytesToWrite, DWORD& dwNumberOfBytesWritten);
Return Value:
Non zero if the write succeeded otherwise FALSE. Use GetLastError()
to
get extended error information.
Parameters:
- lpBuffer -- Points to the buffer containing the data to be written to the pipe.
- dwNumberOfBytesToWrite -- Specifies the number of bytes to write to the pipe.
- dwNumberOfBytesWritten -- Points to the number of bytes written by this function
call.
Write()
sets this value to zero before doing any work or error
checking.
Remarks:
Performs a write to the anonymous pipe in a synchronous manner.
- CAnonymousPipe::Read
- BOOL Read(LPVOID lpBuffer, DWORD dwNumberOfBytesToRead, DWORD& dwNumberOfBytesRead);
Return Value:
Non zero if the read succeeded otherwise FALSE. Use GetLastError()
to
get extended error information.
Parameters:
- lpBuffer -- Points to the buffer to receive the data to be read.
- dwNumberOfBytesToRead -- Specifies the number of bytes to read from the pipe.
- dwNumberOfBytesRead -- Points to the number of bytes read by this function call.
Read
sets this value to zero before doing any work or error checking.
Remarks:
Performs a read from the anonymous pipe in a synchronous manner.
- CAnonymousPipe::Peek
- BOOL Peek(LPVOID lpBuffer, DWORD dwBufferSize, DWORD& dwBytesRead, DWORD& dwTotalBytesAvail, DWORD& dwBytesLeftThisMessage);
Return Value:
Non zero if the function succeeds otherwise FALSE. Use GetLastError()
to
get extended error information.
Parameters:
- lpBuffer -- Points to a buffer that receives data read from the pipe. This parameter
can be NULL if no data is to be read.
- dwBufferSize -- Specifies the size, in bytes, of the buffer specified by the
lpBuffer parameter. This parameter is ignored if lpBuffer is NULL.
- dwBytesRead -- 32-bit variable that receives the number of bytes read from the pipe.
- dwTotalBytesAvail -- 32-bit variable that receives the total number of bytes available
to be read from the pipe.
- dwBytesLeftThisMessage -- 32-bit variable that receives the number of bytes remaining
in this message. This parameter will be zero for byte-type named pipes.
Remarks:
Copies data from the pipe into a buffer without removing it from the pipe. It also returns
information about data in the pipe.
- CAnonymousPipe::IsOpen
- BOOL IsOpen() const;
Return Value:
Non zero if the pipe is open otherwise FALSE.
- CAnonymousPipe::AssertValid
- virtual void AssertValid();
Remarks:
Standard MFC override which performs a validity check on this instance.
- CAnonymousPipe::Dump
- virtual void Dump(CDumpContext& dc) const;
Parameters:
- dc -- The diagnostic dump context for dumping, usually
afxDump
.
Remarks:
Standard MFC override which performs a dump to the dump context as provided by dc.
Planned Enhancements
- Package the code up into an OCX to allow non MFC apps to use the code.
- Provide a sample application with 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
PJ Naughter
Email: pjn@indigo.ie
Web: http://www.naughter.com
2 August 1998