code: def connect_to_pipe(pipe_name):
      
      pipe_handle = windll.kernel32.CreateFileW(
          pipe_name,
          DWORD(GENERIC_READ | GENERIC_WRITE | FILE_WRITE_ATTRIBUTES),
          DWORD(0),  # No sharing.
          None,  # Default security attributes.
          DWORD(OPEN_EXISTING),  # dwCreationDisposition.
          FILE_FLAG_OVERLAPPED,  # dwFlagsAndAttributes.
          None  # hTemplateFile,
      )
      if pipe_handle == INVALID_HANDLE_VALUE:
          raise Exception('Invalid handle. Connecting to pipe %r failed.' % pipe_name)
  
      # Turn pipe into message mode.
      dwMode = DWORD(PIPE_READMODE_MESSAGE)
      windll.kernel32.SetNamedPipeHandleState(
          pipe_handle,
          byref(dwMode),
          None,
          None)
  
      return pipe_handle
docs: Connect to a new pipe in message mode.