WaitNamedPipe Function
Applies to: Windows, Windows Server
Header: Winbase.h (include Windows.h)
LPCTSTR lpNamedPipeName,
DWORD nTimeOut
);
The WaitNamedPipe function determines whether a named pipe server is running and has an instance available. If the pipe is not available, the function waits for a specified amount of time for a server process to create an instance of the named pipe.
Parameters
lpNamedPipeName
[in] Pointer to a null-terminated string that specifies the name of the named pipe. Pipe names use the form \\.\pipe\pipe-name.
nTimeOut
[in] Specifies the time-out duration, in milliseconds. This parameter can be one of the following values:
NMPWAIT_USE_DEFAULT_WAIT: Waits indefinitely for a server process to create an instance of the named pipe.NMPWAIT_WAIT_FOREVER: Waits indefinitely for a server process to create an instance of the named pipe. Equivalent toNMPWAIT_USE_DEFAULT_WAIT.NMPWAIT_WAIT_CLIENT_DISCONNECT: Waits indefinitely for a server process to create an instance of the named pipe.- A value greater than zero: Specifies the time-out duration in milliseconds.
0: Returns immediately without waiting. The function returnsTRUEif a server process has created an instance of the pipe, andFALSEotherwise.
Return value
If the function succeeds, the return value is non-zero. This means that a server process has created an instance of the specified named pipe.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The WaitNamedPipe function is used by a client process to wait for a named pipe server to create an instance of a named pipe before attempting to open it.
If the named pipe is not available within the specified time-out period, the function returns FALSE and GetLastError returns ERROR_SEM_TIMEOUT.
If the nTimeOut parameter is 0, the function checks for the existence of the pipe and returns immediately.
Important
Using WaitNamedPipe with a time-out value of 0 is generally not recommended for waiting on named pipes. Instead, use CreateFile with appropriate flags and error checking to handle cases where the pipe is not immediately available.
Note
The name of the named pipe must include the server name and pipe name. For example, \\ServerName\PipeName.
Requirements
Minimum supported client: Windows XP
Minimum supported server: Windows Server 2003
Header: Winbase.h
Library: Kernel32.lib
DLLs: Kernel32.dll