Platform SDK: Interprocess Communications

CallNamedPipe

The CallNamedPipe function connects to a message-type pipe (and waits if an instance of the pipe is not available), writes to and reads from the pipe, and then closes the pipe.

BOOL CallNamedPipe(
  LPCTSTR lpNamedPipeName,  // pipe name
  LPVOID lpInBuffer,        // write buffer
  DWORD nInBufferSize,      // size of write buffer
  LPVOID lpOutBuffer,       // read buffer
  DWORD nOutBufferSize,     // size of read buffer
  LPDWORD lpBytesRead,      // number of bytes read
  DWORD nTimeOut            // time-out value
);

Parameters

lpNamedPipeName
[in] Pointer to a null-terminated string specifying the pipe name.
lpInBuffer
[in] Pointer to the buffer containing the data written to the pipe.
nInBufferSize
[in] Specifies the size, in bytes, of the write buffer.
lpOutBuffer
[out] Pointer to the buffer that receives the data read from the pipe.
nOutBufferSize
[in] Specifies the size, in bytes, of the read buffer.
lpBytesRead
[out] Pointer to a variable that receives the number of bytes read from the pipe.
nTimeOut
[in] Specifies the number of milliseconds to wait for the named pipe to be available. In addition to numeric values, the following special values can be specified.
Value Meaning
NMPWAIT_NOWAIT Does not wait for the named pipe. If the named pipe is not available, the function returns an error.
NMPWAIT_WAIT_FOREVER Waits indefinitely.
NMPWAIT_USE_DEFAULT_WAIT Uses the default time-out specified in a call to the CreateNamedPipe function.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Calling CallNamedPipe is equivalent to calling the CreateFile (or WaitNamedPipe, if CreateFile cannot open the pipe immediately), TransactNamedPipe, and CloseHandle functions. CreateFile is called with an access flag of GENERIC_READ | GENERIC_WRITE, an inherit handle flag of FALSE, and a share mode of zero (indicating no sharing of this pipe instance).

If the message written to the pipe by the server process is longer than nOutBufferSize, CallNamedPipe returns FALSE, and GetLastError returns ERROR_MORE_DATA. The remainder of the message is discarded, because CallNamedPipe closes the handle to the pipe before returning.

CallNamedPipe fails if the pipe is a byte-type pipe.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Pipes Overview, Pipe Functions, CloseHandle, CreateFile, CreateNamedPipe, TransactNamedPipe, WaitNamedPipe