TransactNamedPipe

  BOOL TransactNamedPipe(hNamedPipe, lpvWriteBuf, cbWriteBuf, lpvReadBuf, cbReadBuf, lpcbRead, lpo)    
  HANDLE hNamedPipe; /* named-pipe handle */
  LPVOID lpvWriteBuf; /* address of the write buffer */
  DWORD cbWriteBuf; /* size of the write buffer in bytes */
  LPVOID lpvReadBuf; /* address of the read buffer */
  DWORD cbReadBuf; /* size of the read buffer in bytes */
  LPDWORD lpcbRead; /* address of DWORD for bytes actually read */
  LPOVERLAPPED lpo; /* address of overlapped structure */

The TransactNamedPipe function writes data to and reads data from a named pipe.

This function fails if the server did not create the pipe as a message mode pipe, or if the pipe handle is not in message readmode. A pipe handle can be set to message readmode with the SetNamedPipeHandleState function. TransactNamedPipe also fails if the named pipe contains any unread data. A named pipe's blocking state has no effect on the TransactNamedPipe function. This function does not complete until data is written into the lpvReadBuf buffer. The lpo parameter is available to allow an application to continue processing while the operation takes place.

Parameters

hNamedPipe

Specifies a handle to a named pipe returned by the CreateNamedPipe or CreateFile functions.

lpvWriteBuf

Points to the buffer containing the data that is written to the pipe.

cbWriteBuf

Specifies the size (in bytes) of the write buffer.

lpvReadBuf

Points to the buffer that receives the data read from the pipe.

cbReadBuf

Specifies the size (in bytes) of the read buffer.

lpcbRead

Points to the variable that receives the number of bytes actually read from the pipe.

lpo

Points to an OVERLAPPED structure. If this parameter is NULL or the handle was created without FILE_FLAG_OVERLAPPED, TransactNamedPipe will not return until the operation completes.

If lpo is not NULL and FILE_FLAG_OVERLAPPED was specified when the handle was created, TransactNamedPipe may return FALSE with GetLastError returning ERROR_IO_PENDING to allow the caller to continue processing while the operation completes.

The OVERLAPPED structure should contain an event object which is set to the Not-Signalled state before TransactNamedPipe returns, and is set to the Signalled state when the transaction is complete.

If the OVERLAPPED structure does not contain an event object, the pipe handle is used to signal completion. Use of the pipe handle for this purpose is not recommended due to complications when simultaneous overlapped operations are performed on the same pipe handle. GetOverlappedResult is used to determine the result when GetLastError returns ERROR_IO_PENDING.

The OVERLAPPED structure has the following form:

typedef struct _OVERLAPPED { /* o */

DWORD Internal;

DWORD InternalHigh;

DWORD Offset;

DWORD OffsetHigh;

HANDLE hEvent;

} OVERLAPPED;

typedef OVERLAPPED *LPOVERLAPPED;

Return Value

The return value is TRUE if the function was successful, or FALSE if an error occurred. To obtain extended error information, use the GetLastError function.

Comments

If the message to be read is longer than cbReadBuf, TransactNamedPipe will return FALSE, and the GetLastError function will return ERROR_MORE_DATA. The remainder of the message may be read by a subsequent ReadFile or PeekNamedPipe.

See Also

CreateNamedPipe