TransactNamedPipe Function

Performs a bidirectional synchronous I/O operation on the specified named pipe.

Description

The TransactNamedPipe function performs a bidirectional synchronous I/O operation on the specified named pipe. This function is useful for sending a request to a named pipe server and receiving a response in a single operation.

It combines a write operation (sending the request) and a read operation (receiving the response) into one atomic transaction. The operation completes when either the specified timeout has expired or the entire transaction is complete.

Syntax

BOOL TransactNamedPipe(
        HANDLE              hNamedPipe,
        LPINOUT_BUFFER      lpvTransaction,
        DWORD               nTransactionSize,
        LPBOOL              pfPending,
        LPOVERLAPPED        lpOverlapped,
        LPDWORD             lpcbBytesTransferred
    );

Parameters

Parameter Description
hNamedPipe A handle to the named pipe. This handle must have been created by the CreateNamedPipe function and opened with the FILE_FLAG_OVERLAPPED flag.
lpvTransaction A pointer to a buffer that contains the data to be written to the pipe. The server writes its response to this same buffer. The buffer must be large enough to hold the data sent by the client and the data returned by the server.
nTransactionSize The size of the buffer pointed to by lpvTransaction, in bytes.
pfPending A pointer to a boolean value that receives TRUE if the I/O operation is pending, or FALSE otherwise. This parameter is only relevant if lpOverlapped is not NULL.
lpOverlapped A pointer to an OVERLAPPED structure that is used for asynchronous operation. If this parameter is NULL, the function blocks until the operation is complete.
lpcbBytesTransferred A pointer to a DWORD value that receives the number of bytes transferred, in bytes. This value is only valid if the operation is completed synchronously. If the operation is asynchronous, the value is valid when the OVERLAPPED operation completes.

Return Value

Value Description
TRUE If the function succeeds, the return value is TRUE.
FALSE If the function fails, the return value is FALSE. To get extended error information, call GetLastError.

Remarks

Important: For asynchronous operations, ensure that the hNamedPipe handle was created with the FILE_FLAG_OVERLAPPED flag. The OVERLAPPED structure should be properly initialized, and the event object within it should be used to wait for completion.

See Also