Ejemplo n.º 1
0
        public static void CreatePipe(out SafeFileHandle parentHandle, out SafeFileHandle childHandle, bool parentInputs)
        {
            AdvApi32PInvoke.SECURITY_ATTRIBUTES lpPipeAttributes = new AdvApi32PInvoke.SECURITY_ATTRIBUTES();
            lpPipeAttributes.bInheritHandle = true;
            SafeFileHandle hWritePipe = null;

            try
            {
                if (parentInputs)
                {
                    CreatePipeWithSecurityAttributes(out childHandle, out hWritePipe, lpPipeAttributes, 0);
                }
                else
                {
                    CreatePipeWithSecurityAttributes(out hWritePipe, out childHandle, lpPipeAttributes, 0);
                }

                if (!Kernel32.DuplicateHandle(Kernel32.GetCurrentProcess(), hWritePipe, Kernel32.GetCurrentProcess(), out parentHandle,
                                              0, false, Kernel32.DUPLICATE_SAME_ACCESS))
                {
                    throw new Win32Exception();
                }
            }
            finally
            {
                if ((hWritePipe != null) && !hWritePipe.IsInvalid)
                {
                    hWritePipe.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public static void CreatePipe(out SafeFileHandle parentHandle, out SafeFileHandle childHandle, bool parentInputs)
        {
            AdvApi32PInvoke.SECURITY_ATTRIBUTES lpPipeAttributes = new AdvApi32PInvoke.SECURITY_ATTRIBUTES();
            lpPipeAttributes.bInheritHandle = true;
            SafeFileHandle hWritePipe = null;
            try
            {
                if (parentInputs)
                {
                    CreatePipeWithSecurityAttributes(out childHandle, out hWritePipe, lpPipeAttributes, 0);
                }
                else
                {
                    CreatePipeWithSecurityAttributes(out hWritePipe, out childHandle, lpPipeAttributes, 0);
                }

                if (!Kernel32.DuplicateHandle(Kernel32.GetCurrentProcess(), hWritePipe, Kernel32.GetCurrentProcess(), out parentHandle,
                    0, false, Kernel32.DUPLICATE_SAME_ACCESS))
                {
                    throw new Win32Exception();
                }
            }
            finally
            {
                if ((hWritePipe != null) && !hWritePipe.IsInvalid)
                {
                    hWritePipe.Close();
                }
            }
        }
Ejemplo n.º 3
0
 public static extern bool CreatePipe(out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe,
                                      ref AdvApi32PInvoke.SECURITY_ATTRIBUTES lpPipeAttributes, uint nSize);
Ejemplo n.º 4
0
 private static void CreatePipeWithSecurityAttributes(out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe, AdvApi32PInvoke.SECURITY_ATTRIBUTES lpPipeAttributes, uint nSize)
 {
     if ((!Kernel32.CreatePipe(out hReadPipe, out hWritePipe, ref lpPipeAttributes, nSize) || hReadPipe.IsInvalid) || hWritePipe.IsInvalid)
     {
         throw new Win32Exception();
     }
 }