Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- DOS 5.0 Ref. - <b>function 46h force duplicate file handle</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Function 46h            Force Duplicate File Handle

    Forces one handle to refer to the same file or device as another
    handle.

        Entry   AH = 46h
                BX = Handle of file or device
                CX = New handle for same file or device

        Return  Nothing (CF clear)
                or
                AX = Error code, if CF is set
                     | 04h No handles available
                     | 06h Invalid handle

    ------------------------------------------------------------------

    After a program uses this function, both handles can be used to
    read from or write to the file or device specified by CX. Moving
    the file pointer with either handle moves the file pointer for the
    other handle.

    If the second handle refers to an open file, that file is closed
    before the handle is set equal to the first handle.

    ------------------------------------------------------------------

    Example

        ; Redirect output to StdOut to a file,
        ; e.g. for a child program
        mov     bx,STDOUT
        mov     ah,45h                  ; Duplicate Handle
        int     21h
        jc      @@error
        mov     [stdout_dup],ax         ; Store dup. handle
        mov     bx,[file_handle]        ; Handle of an open file
        mov     cx,STDOUT               ; Handle to be redirected
        mov     ah,46h                  ; Force Duplicate Handle
        int     21h
        jc      @@error
        ; Output to standard output now redirected
        ; ...
        ; Cancel the redirection
        mov     bx,[stdout_dup]         ; Previous STDOUT dup.
        mov     cx,STDOUT               ; Handle to be redirected
        mov     ah,46h                  ; Force Duplicate Handle
        int     21h
        jc      @@error
        mov     ah,3eh                  ; Close stdout_dup
        int     21h
        ;...

See Also: 45h 67h 59h 4400h StdDevices

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson