# File lib/childprocess/windows/functions.rb, line 5
      def self.create_proc(cmd, opts = {})
        cmd_ptr = FFI::MemoryPointer.from_string cmd

        flags   = 0
        inherit = !!opts[:inherit]

        flags |= DETACHED_PROCESS if opts[:detach]

        si = StartupInfo.new
        pi = ProcessInfo.new

        if opts[:stdout] || opts[:stderr]
          si[:dwFlags] ||= 0
          si[:dwFlags] |= STARTF_USESTDHANDLES
          inherit = true

          si[:hStdOutput] = handle_for(opts[:stdout].fileno) if opts[:stdout]
          si[:hStdError]  = handle_for(opts[:stderr].fileno) if opts[:stderr]
        end

        if opts[:duplex]
          read_pipe_ptr  = FFI::MemoryPointer.new(:pointer)
          write_pipe_ptr = FFI::MemoryPointer.new(:pointer)
          sa         = SecurityAttributes.new(:inherit => true)

          ok = create_pipe(read_pipe_ptr, write_pipe_ptr, sa, 0)
          ok or raise Error, last_error_message

          read_pipe = read_pipe_ptr.read_pointer
          write_pipe = write_pipe_ptr.read_pointer

          si[:hStdInput] = read_pipe
        end

        ok = create_process(nil, cmd_ptr, nil, nil, inherit, flags, nil, nil, si, pi)
        ok or raise Error, last_error_message

        close_handle pi[:hProcess]
        close_handle pi[:hThread]

        if opts[:duplex]
          opts[:stdin] = io_for(duplicate_handle(write_pipe), File::WRONLY)
          close_handle read_pipe
          close_handle write_pipe
        end

        pi[:dwProcessId]
      end