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

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • Live Event Date: September 16, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you starting an on-premise-to-cloud data migration project? Have you thought about how much space you might need for your online platform or how to handle data that might be related to users who no longer exist? If these questions or any other concerns have been plaguing you about your migration project, check out this eSeminar. Join our speakers Betsy Bilhorn, VP, Product Management at Scribe, Mike Virnig, PowerSucess Manager and Michele …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds