 0}
        } -setvars -maxleftover 0

        # TBD - is 10 an appropriate number of events to read?
        set events [evt_next $hq -timeout 0 -count 10 -status status]
        if {[llength $events]} {
            trap {
                set result [evt_decode_events $events -lcid $lcid -ignorestring "" -message -levelname -taskname]
            } finally {
                evt_close {*}$events
            }
            return $result
        }

        # No events were returned. Check status whether it is fatal error
        # or not. SUCCESS, NO_MORE_ITEMS, TIMEOUT, INVALID_OPERATION
        # are acceptable. This last happens when another EvtNext is done
        # after an NO_MORE_ITEMS is already returned.
        if {$status == 0 || $status == 259 || $status == 1460 || $status == 4317} {
            # Even though $events is empty, still pass it in so it returns
            # an empty record array in the correct format.
            return [evt_decode_events $events -lcid $lcid -ignorestring "" -message -levelname -taskname]
        } else {
            win32_error $status
        }
    }

    proc twapi::winlog_subscribe {channelpath} {
        variable _winlog_handles
        lassign [evt_subscribe $channelpath -ignorequeryerrors] hq signal
        dict set _winlog_handles $hq signal $signal
        dict set _winlog_handles $hq session NULL; # local session
        return [list $hq $signal]
    }

    interp alias {} twapi::winlog_clear {} twapi::evt_clear_log

    proc twapi::winlog_backup {channel outpath} {
        evt_export_log $outpath -channel $channel
        return
    }

} else {

    proc twapi::winlog_read {hq args} {
        parseargs args {
            {lcid.int 0}
        } -setvars -maxleftover 0

        variable _winlog_handles
        set fields {-channel -taskname -message -providername -eventid -level -levelname -eventrecordid -computer -sid -timecreated}
        set values {}
        set channel [dict get $_winlog_handles $hq channel]
        foreach evl [eventlog_read $hq -direction [dict get $_winlog_handles $hq direction]] {
            # Note order must be same as fields above
            lappend values \
                [list \
                     $channel \
                     [eventlog_format_category $evl -langid $lcid] \
                     [eventlog_format_message $evl -langid $lcid -width -1] \
                     [dict get $evl -source] \
                     [dict get $evl -eventid] \
                     [dict get $evl -level] \
                     [dict get $evl -type] \
                     [dict get $evl -recordnum] \
                     [dict get $evl -system] \
                     [dict get $evl -sid] \
                     [secs_since_1970_to_large_system_time [dict get $evl -timewritten]]]
        }
        return [list $fields $values]
    }

    proc twapi::winlog_subscribe {source} {
        variable _winlog_handles
        lassign [eventlog_subscribe $source] hq hevent
        dict se