CallNamedPipe

  BOOL CallNamedPipe(lpszPipeName, lpvWriteBuf, cbWriteBuf, lpvReadBuf, cbReadBuf, lpcbRead, dwTimeout)    
  LPTSTR lpszPipeName; /* address of the name of the pipe */
  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 */
  DWORD dwTimeout; /* timeout time in milliseconds */

The CallNamedPipe function creates a pipe (and waits if the pipe cannot be created immediately), writes to and reads from the pipe, and then closes the pipe. This function fails if the named pipe contains any unread data, or if the server did not create the pipe as a message mode pipe.

Parameters

lpszPipeName

Points to a null-terminated string specifying the pipe name.

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.

dwTimeout

Specifies the number of milliseconds to wait for the named pipe to be available. In addition to numeric values, the following special values are available:

Value Meaning

NMPWAIT_NO_WAIT Do not wait for the named pipe. (If the named pipe is not available, the function returns an error.)
NMPWAIT_WAIT_FOREVER Wait indefinitely.
NMPWAIT_USE_DEFAULT_WAIT Use default timeout specified in call to CreateNamedPipe.

Return Value

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

Comments

This function is equivalent to calling CreateFile (or WaitNamedPipe if CreateFile cannot open the pipe immediately), TransactNamedPipe, and CloseHandle. CreateFile is called with a desired 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).

The CallNamedPipe function may be used as either a wide-character function (where text arguments must use Unicode) or an ANSI function (where text arguments must use characters from the Windows 3.x character set installed).

If the message written to the pipe by the server is longer than cbReadBuf, CallNamedPipe will return FALSE, and the GetLastError function will return ERROR_MORE_DATA. The remainder of the message will be discarded because CallNamedPipe closes the handle to the pipe before returning.

See Also

CreateFile, CreateNamedPipe, TransactNamedPipe, WaitNamedPipe