GetCurrentProcess() and GetCurrentProcessId()

本文详细解释了 GetCurrentProcess() 函数的作用、返回值类型、与伪句柄的关系,以及如何在子进程中获取父进程的句柄。重点讨论了句柄的继承性、关闭操作以及使用 DuplicateHandle 和 OpenProcess 函数的场景。

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 that can 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()来得到


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值