+ /* Handle all open modes */
+ if (dwOpenMode & PIPE_ACCESS_OUTBOUND)
+ {
+ ShareAccess |= FILE_SHARE_READ;
+ DesiredAccess |= GENERIC_WRITE;
+ }
+ if (dwOpenMode & PIPE_ACCESS_INBOUND)
+ {
+ ShareAccess |= FILE_SHARE_WRITE;
+ DesiredAccess |= GENERIC_READ;
+ }
+
+ /* Handle the type flags */
+ if (dwPipeMode & PIPE_TYPE_MESSAGE)
+ {
+ WriteModeMessage = FILE_PIPE_MESSAGE_TYPE;
+ }
+ else
+ {
+ WriteModeMessage = FILE_PIPE_BYTE_STREAM_TYPE;
+ }
+
+ /* Handle the mode flags */
+ if (dwPipeMode & PIPE_READMODE_MESSAGE)
+ {
+ ReadModeMessage = FILE_PIPE_MESSAGE_MODE;
+ }
+ else
+ {
+ ReadModeMessage = FILE_PIPE_BYTE_STREAM_MODE;
+ }
+
+ /* Handle the blocking mode */
+ if (dwPipeMode & PIPE_NOWAIT)
+ {
+ NonBlocking = FILE_PIPE_COMPLETE_OPERATION;
+ }
+ else
+ {
+ NonBlocking = FILE_PIPE_QUEUE_OPERATION;
+ }
+
+ /* Check if we have a timeout */
+ if (nDefaultTimeOut)
+ {
+ /* Convert the time to NT format */
+ DefaultTimeOut.QuadPart = UInt32x32To64(nDefaultTimeOut, -10000);
+ }
+ else
+ {
+ /* Use default timeout of 50 ms */
+ DefaultTimeOut.QuadPart = -500000;
+ }
+
+ /* Now create the pipe */
+ Status = NtCreateNamedPipeFile(&PipeHandle,
+ DesiredAccess,
+ &ObjectAttributes,
+ &Iosb,
+ ShareAccess,
+ FILE_OPEN_IF,
+ CreateOptions,
+ WriteModeMessage,
+ ReadModeMessage,
+ NonBlocking,
+ nMaxInstances,
+ nInBufferSize,
+ nOutBufferSize,
+ &DefaultTimeOut);
+
+ /* Free the name */
+ RtlFreeUnicodeString(&NamedPipeName);
+
+ /* Check status */
+ if (!NT_SUCCESS(Status))
+ {
+ /* Failed to create it */
+ DPRINT1("NtCreateNamedPipe failed (Status %x)!\n", Status);
+ SetLastErrorByStatus (Status);
+ return INVALID_HANDLE_VALUE;
+ }