BOOL CreatePipe(phRead, phWrite, lpsa, cbPipe) | |||||
PHANDLE phRead; | /* address of variable for read handle | */ | |||
PHANDLE phWrite; | /* address of variable for write handle | */ | |||
LPSECURITY_ATTRIBUTES lpsa; | /* optional security attributes | */ | |||
DWORD cbPipe; | /* number of bytes reserved for pipe | */ |
The CreatePipe function creates an anonymous pipe. The function creates the pipe, assigning the specified pipe size to the storage buffer, and also creates handles that the process can use to read from and write to the buffer in subsequent calls to the ReadFile and WriteFile functions.
phRead
Points to the variable that receives the read handle for the pipe.
phWrite
Points to the variable that receives the write handle for the pipe.
lpsa
Points to a SECURITY_ATTRIBUTES data structure that specifies the security attributes for the pipe. The file system must support this parameter for it to have an effect.
The SECURITY_ATTRIBUTES structure has the following format:
typedef struct _SECURITY_ATTRIBUTES { /* sa */
DWORD nLength;
LPVOID lpSecurityDescriptor;
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES;
If lpsa is NULL, the pipe is created without a security descriptor, and the pipe handle is not inherited by child processes.
cbPipe
Specifies the requested buffer size for the pipe. This is only a suggestion and is used by the operating system to calculate an appropriate buffering mechanism. If this parameter is zero, the default buffer size is used.
The return value is TRUE if the pipe was created, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information.
When an application uses the WriteFile function to write to a pipe, the write operation may not complete if the pipe buffer is full. The write operation will complete when a read operation (using the ReadFile function) makes more buffer space available.
CreateNamedPipe, DuplicateHandle