GetCurrentProcess() and GetCurrentProcessId()

来源:互联网 发布:淘宝标题带特价 编辑:程序博客网 时间:2024/06/03 12:55

MSDN:

GetCurrentProcess() 

The return value is a pseudo handle to the current process.

Remark

Pseudo handles are not inherited by child processes.

A process can create a "real" handle to itself that is valid in the context of other processes, or thatcan be inherited by other processes, by specifying the pseudo handle as the source handle in a call to the DuplicateHandle function.A process can also use the OpenProcess function to open a real handle to itself.

The pseudo handle need not be closed when it is no longer needed. Calling the CloseHandle function with a pseudo handle has no effect. If the pseudo handle is duplicated byDuplicateHandle, the duplicate handle must be closed.


HANDLE handle = GetCurrentProcess();

该handle不能被子进程继承使用!

如果要在子进程中获取父进程的handle,可以通过传递ProcessID给子进程,子进程中使用GetCurrentProcessId()来得到


0 0
原创粉丝点击