Click here to Skip to main content
15,896,493 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello All,
I am working on Com Server and client Communication and i got a problem while creating File on a named pipe.
The scenario is Like This,
1. Com Server Creates a named pipe.

C++
hWritePipe = CreateNamedPipe( PIPE_NAME,        // pipe name
                                 PIPE_ACCESS_DUPLEX ,         // read/write access
                                 PIPE_TYPE_MESSAGE |          // message type pipe
                                 PIPE_READMODE_MESSAGE |      // message-read mode
                                 PIPE_NOWAIT,                 // blocking mode
                                 PIPE_UNLIMITED_INSTANCES,    // max. instances
                                 PIPE_BUFFER_SIZE,            // output buffer size
                                 PIPE_BUFFER_SIZE             // input buffer size
                                 PIPE_TIMEOUT,                // client time-out
                                 NULL);                       // attribute
ConnectNamedPipe(hWritePipe, NULL);


2. Client1 open the com server and gets the pipe name and opens it with CreateFile as follows,

C++
handle1 = CreateFile( m_chWritePipeName,      // pipe 
GENERIC_READ|GENERIC_WRITE,     // read access
FILE_SHARE_READ|FILE_SHARE_WRITE,                               // no sharing
NULL,                           // no security attributes
OPEN_EXISTING,                  // opens existing pipe
0,                              // default attributes
NULL);   
// no template file

handle1 is proper and we are able to communicate with server

3. Open the second instance of same client say client2.Client2 also gets the pipe name and tries to open(Same CreateFile call) the pipe.But in this case we are getting Invalid handle and GetLastError() is 0xe7(All pipe instances are busy).

Is it possible to open the Named pipe by multiple process?

Thanks in advance.
Posted

1 solution

You can't use the same handle in multiple processes.

MSDN seems to be down right at the moment but ask Google about the DuplicateHandle() API. My recollection is that the MSDN info tells the whole story for you.

This link[^] also seems to provide a good answer for you...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900