Function 46h Force Duplicate File Handle

mov bx, OpenHandle ;handle of file or device

mov cx, DuplicateHandle ;new handle for same file or device

mov ah, 46h ;Force Duplicate File Handle

int 21h

jc error_handler ;carry set means error

Force Duplicate File Handle (Function 46h) forces the specified duplicate handle to identify the same open file or device identified by the OpenHandle parameter.

Parameters

OpenHandle

Identifies an open file or device.

DuplicateHandle

Specifies an integer value for the new handle. This integer must not exceed the current limit as specified by Set Maximum Handle Count (Function 67h).

Return Value

If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:

Value Name

0004h ERROR_TOO_MANY_OPEN_FILES
0006h ERROR_INVALID_HANDLE

Comments

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

If DuplicateHandle identifies an open file, MS-DOS closes that file.

See Also

Function 45h Duplicate File Handle
Function 67h Set Maximum Handle Count