bool duplicate_handle(handle source,
                      handle file,
                      handle target,
                      handle* result,
                      unsigned access,
                      bool inherit,
                      unsigned options)

This function duplicates the handle of an object.


handle source

The handle of the process containing the file.

handle file

The handle of the file to be duplicated.

handle target

The handle of the process that receives the duplicated handle.

handle* result

A pointer to a variable that receives the duplicated handle.

unsigned access

Generic access flags (for files, console buffers, communications devices etc) are as follows.

access_type::generic_read Read access is required.
access_type::generic_write Write access is required.

Other applicable access flags are shown below.

exclusive exclusive_access
file_mapping file_mapping_access
event event_access
registry key_access
process process_access
thread thread_access

bool inherit

true The handle can be inherited.
false The handle cannot be inherited.

unsigned options

Options when duplicating - see enumeration duplicate_option.



true The handle was successfuly duplicated.
false The call to this function failed.


Either the source or target process can duplicate a handle. The source and target process may be the same. Some form of interprocess communication is necessary to transfer handles between processes.

The state of the file is identical for both handles.