<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def connect_to_pipe(pipe_name):
 """ Connect to a new pipe in message mode. """

    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