Named Pipe Wrapper for Win32 Platforms

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

Background

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.

Method

Description

Create

Creates and registers the neccessary pipe(s).

Close

Closes the pipe(s).

ReadPipe

Performs read operation on the pipe.

WritePipe

Performs write operation on the pipe.

GetLastError

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.

Server

Client

Downloads

Download demo project - 40 Kb
Download source - 6 Kb


Comments

  • 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?

    Thanks,
    Alon Weiss.

    Reply
  • 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 !

    Reply
  • 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;

    ...
    }

    Reply
  • 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.

    Reply
  • 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?)

    Reply
  • 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?

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • With the average hard drive now averaging one terabyte in size, the fallout from the explosion of user-created data has become an overwhelming volume of potential evidence that law-enforcement and corporate investigators spend countless hours examining. Join Us and SANS' Rob Lee for our 45-minute webinar, A Triage and Collection Strategy for Time-Sensitive Investigations, will demonstrate how to: Identify the folders and files that often contain key insights Reduce the time spent sifting through content by …

Most Popular Programming Stories

More for Developers

RSS Feeds