DuplicateHandle妙用無窮啊。
DuplicateHandle(GetCurrentProcess(),GetCurrentProcess(),
GetCurrentProcess(),&hReadDup,
0, FALSE,DUPLICATE_SAME_ACCESS)
的用處就不小:)
誰能解釋下上面代碼的用處?
6 个解决方案
查MSDN:用法如下
The DuplicateHandle function duplicates an object handle.
BOOL DuplicateHandle(
HANDLE hSourceProcessHandle, // handle to the source process
HANDLE hSourceHandle, // handle to duplicate
HANDLE hTargetProcessHandle, // handle to process to duplicate to
LPHANDLE lpTargetHandle, // pointer to duplicate handle
DWORD dwDesiredAccess, // access for duplicate handle
BOOL bInheritHandle, // handle inheritance flag
DWORD dwOptions // optional actions
);
Parameters
hSourceProcessHandle
Handle to the process with the handle to duplicate.
Windows NT: The handle must have PROCESS_DUP_HANDLE access.
hSourceHandle
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 following Remarks section.
hTargetProcessHandle
Handle to the process that is to receive the duplicated handle. The handle must have PROCESS_DUP_HANDLE access.
lpTargetHandle
Pointer to a variable receiving the value of the duplicate handle. This handle value is valid in the context of the target process.
If lpTargetHandle is NULL, 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.
dwDesiredAccess
Specifies the access requested for the new handle. This parameter is ignored if the dwOptions parameter specifies the DUPLICATE_SAME_ACCESS flag. Otherwise, the flags that can be specified depend on the type of object whose handle is being duplicated. For the flags that can be specified for each object type, see the following Remarks section. Note that the new handle can have more access than the original handle.
bInheritHandle
Indicates whether the handle is inheritable. If TRUE, the duplicate handle can be inherited by new processes created by the target process. If FALSE, the new handle cannot be inherited.
dwOptions
Specifies optional actions. This parameter can be zero, or any combination of the following flags: Value Meaning
DUPLICATE_CLOSE_SOURCE Closes the source handle. This occurs regardless of any error status returned.
DUPLICATE_SAME_ACCESS Ignores the dwDesiredAccess parameter. The duplicate handle has the same access as the source handle.
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.
極有可能為了跨進程共享handle(kernel object)