DuplicateHandle (Windows CE 5.0)

Send Feedback

This function duplicates an object handle. The duplicate handle refers to the same object as the original handle. Therefore, any changes to the object are reflected through both handles.

BOOL DuplicateHandle(HANDLEhSourceProcessHandle,HANDLEhSourceHandle,HANDLEhTargetProcessHandle,LPHANDLElpTargetHandle,DWORDdwDesiredAccess,BOOLbInheritHandle,DWORDdwOptions);

Parameters

  • hSourceProcessHandle
    [in] Handle to the process with the handle to duplicate.

  • hSourceHandle
    [in] Handle to duplicate. This is an open object handle that is valid in the context of the source process. For a list of objects whose handles can be duplicated, see the Remarks section.

  • hTargetProcessHandle
    [in] Handle to the process that is to receive the duplicated handle. The handle must have PROCESS_DUP_HANDLE access.

  • lpTargetHandle
    [out] Pointer to a variable that receives the value of the duplicate handle. This handle value is valid in the context of the target process. Cannot be NULL.

  • dwDesiredAccess
    [in] Currently ignored in Windows CE.

  • bInheritHandle
    [in] Indicates whether the handle is inheritable. Must be set to FALSE.

    If FALSE, the new handle cannot be inherited.

  • dwOptions
    [in] Specifies optional actions. This parameter can be any combination of the following flags, which include DUPLICATE_SAME_ACCESS.

    Value Description
    DUPLICATE_CLOSE_SOURCE Closes the source handle. This occurs regardless of any error status returned.
    DUPLICATE_SAME_ACCESS The duplicate handle has the same access as the source handle. This flag must be specified for Windows CE.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Either the source process or the target process can call DuplicateHandle, which can also be invoked where the source and target process are the same.

The duplicating process uses the GetCurrentProcess function to get a handle of itself. To get the other process handle, it might be necessary to use some form of interprocess communication, for example, shared memory, to communicate the process identifier to the duplicating process. This identifier is then used in the OpenProcess function to open a handle.

If the process that calls DuplicateHandle is not the target process, the duplicating process must use interprocess communication to pass the value of the duplicate handle to the target process.

DuplicateHandle can duplicate handles only to the types of objects in the following table.

Handle Description
Event Returned by CreateEvent or OpenEvent.
Mutex Returned by CreateMutex.
Semaphore Returned by CreateSemaphore.

Note   Each object type, such as memory maps, semaphores, events, message queues, mutexes, and watchdog timers, has its own separate namespace. Empty strings, "", are handled as named objects. On Windows desktop-based platforms, synchronization objects all share the same namespace.

Requirements

OS Versions: Windows CE .NET 4.0 and later.
Header: Windows.h.
Link Library: Coredll.lib.

See Also

OpenProcess | CreateEvent | OpenEvent | CreateFileMapping | CreateMutex | CreateProcess | GetCurrentProcess | CreateSemaphore | CreateThread | GetCurrentThread | CloseHandle

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.