Named Pipe Wrapper for Win32 Platforms

Environment: VC6/MFC , Win9X/WinME/NT40/W2k


Using pipes is not too complicated on WindowsNT platforms, but on Win9X it4s not that easy because named pipes are not supported.

The wrapper

"cPipe" is a C++ wrapper class encapsulating named pipes, providing a simple interface to create named pipes and to perform read/write operations. In addition an application-defined callback function, which is called by the framework if data is available, can be specified on creation ( the server side of the sample demonstrates the usage of the callback function ).

"cPipe" contains the following public methods, fully documented within the source.




Creates and registers the neccessary pipe(s).


Closes the pipe(s).


Performs read operation on the pipe.


Performs write operation on the pipe.


Returns the latest cPipe error code.

The sample

The sample provides two tiny applications to demonstrate IPC. For the server-side run "core.exe" and for the client-side run "client.exe". For demonstration the server side just mirrors the data sent by the client application. I tested the sample applications on the following platforms: Win98, NT 4.0, W2k.




Download demo project - 40 Kb
Download source - 6 Kb


  • One-To-Many connection

    Posted by Legacy on 10/06/2003 12:00am

    Originally posted by: Alon Weiss

    I've modified the code a bit to be a 'chat' between the 'core' and the 'client'.
    A very interesting thing i've seen is that when i run two 'clients' and type stuff on the 'core', every Nth message is received by the first 'client', and every other message is receieved by the second.

    Is this normal? How can i modify the code so both clients can recieve the messages?

    Alon Weiss.

  • Excellent ! thank you for your working !

    Posted by Legacy on 06/05/2003 12:00am

    Originally posted by: silentsky

    thanks really !

    good luck to you !

    and happiness to you forever !

  • Problem with MS Terminal Server

    Posted by Legacy on 05/13/2002 12:00am

    Originally posted by: Walter

    Thank you, this is what i needed and it works fine!

    My application runs under the MS Terminal Server environment. If the “core.exe” runs twice for separate sessions, all clients sends on the last starting pipe server. The small addition to your code can solve this problem:

    BOOL cPipe::RegisterPipe ( void )

    // Create registry key

    // insert the desktop HWND bevore the m_PipeName
    CString strDesktopWnd;
    strDesktopWnd.Format("%lu", GetDesktopWindow());

    // m_SubKey = "SOFTWARE\\" + m_GUID + "\\" + m_PipeName;
    m_SubKey = "SOFTWARE\\" + m_GUID + "\\" + strDesktopWnd + "\\" + m_PipeName;

    BOOL cPipe::RetrievePipe ( void )
    // Open registry key

    // insert the desktop HWND bevore the m_PipeName
    CString strDesktopWnd;
    strDesktopWnd.Format("%lu", GetDesktopWindow());

    // m_SubKey = "SOFTWARE\\" + m_GUID + "\\" + m_PipeName;
    m_SubKey = "SOFTWARE\\" + m_GUID + "\\" + strDesktopWnd + "\\" + m_PipeName;


  • Great work

    Posted by Legacy on 09/28/2001 12:00am

    Originally posted by: Andrea De Nardis

    Thank you very much, this is what exactly needed in order to start w/ my job.

  • Windows 95, single host vs. networked hosts, and general comments

    Posted by Legacy on 08/04/2001 12:00am

    Originally posted by: Marc Clifton

    Windows 95 only supports client-side NAMED pipes. The code works under W95 because it uses anonymous pipes (which are actually given a unique name under NT), and because the server and client applications must reside on the same host. Using anonymous pipes, it is not possible (I think!) to create a server-client application on two hosts over a network.

    This is a good solution to single host named pipes on W95, however I would like to see a bit more robustness in a couple areas: handling of pipe disconnect issues (for example, the server app terminates), threading on the pipe write so the writer doesn't have to wait for the reader to read the data, and read/write buffering (it seems like the buffering could be handled by the pipe class instead of by the app???). Supporting the more general solution of named pipes for NT/W2000 OS's would be great too, thus allowing for distributed hosts (perhaps the OS specific solutions could be derived classes of a general pipe class?)

  • Explanation of Implementation with Win95 Named Pipe

    Posted by Legacy on 08/02/2001 12:00am

    Originally posted by: Steven

    If Win95 named pipes are not supported, how do you support them with this code?

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …

  • The mobile market is white hot. Building a well-crafted product development plan that addresses market research, strategy, design, and development will provide the greatest chance for success. Each phase of an app's lifecycle is critical to the its overall success and feeds into the next step of the process of product development for the app. This white paper examines the five key phases of mobile app creation, one by one, to understand how they work together to help create a successful mobile app.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date