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

被折叠的 条评论
为什么被折叠?



