Kernel32DuplicateHandle(IntPtr, IntPtr, IntPtr, IntPtr, ProcessAccessRights, Boolean, DuplicateHandleOptions) Method

Duplicates an object handle.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", SetLastError = true)]
public static bool DuplicateHandle(
	IntPtr srcProcHandle,
	IntPtr srcHandle,
	IntPtr dstProcHandle,
	ref IntPtr refDstHandle,
	ProcessAccessRights desiredAccess,
	bool inheritHandle,
	DuplicateHandleOptions options
)

Parameters

srcProcHandle  IntPtr
A handle to the process with the handle to be duplicated.

The handle must have the DuplicateHandle access right.

srcHandle  IntPtr
The handle to be duplicated.

This is an open object handle that is valid in the context of the source process.

dstProcHandle  IntPtr
A handle to the process that is to receive the duplicated handle.

The handle must have the DuplicateHandle access right.

refDstHandle  IntPtr
A pointer to a variable that receives the duplicate handle.

This handle value is valid in the context of the target process.

If srcHandle is a pseudo handle returned by GetCurrentProcess or GetCurrentThread, DuplicateHandle(IntPtr, IntPtr, IntPtr, IntPtr, GenericAccessRights, Boolean, DuplicateHandleOptions) converts it to a real handle to a process or thread, respectively.

If refDstHandle is Zero, the function duplicates the handle, but does not return the duplicate handle value to the caller. This behavior exists only for backward compatibility with previous versions of this function. You should not use this feature, as you will lose system resources until the target process terminates.

desiredAccess  ProcessAccessRights
The access requested for the new handle.
inheritHandle  Boolean
A variable that indicates whether the handle is inheritable.

If , the duplicate handle can be inherited by new processes created by the target process.

If , the new handle cannot be inherited.

options  DuplicateHandleOptions
Optional actions. This parameter can be zero.

Return Value

Boolean
If the function succeeds, the return value is .

If the function fails, the return value is .

To get extended error information, call GetLastWin32Error.

Remarks

See Also