Quoted here:
hPipe = CreateFile(
lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL);
How can the above code make sure that it actually opens a pipe and not an existing hard disk file?
BTW, how can I open a persistent pipe so that can be used multiple times?
A pipe name must start with
\\.\pipe\(or more generally,\\servername\pipe\). A file on a hard drive never will have that prefix, so you just need to ensure that the name has that prefix. Alternatively, you can useCallNamedPipe, which (I’m pretty sure) will fail if passed a name of something other than a named pipe.I’m not sure what your second question is intended to ask — you can send as many messages/as much data over a pipe as you wish. If you mean opening a single named pipe on the server that can be used by multiple clients, the last parameter when you call
CreateNamedPipespecifies the maximum number of concurrent instances (clients, in essence) allowed.