一直不明白伪句柄有什么用,请详细举例说明伪句柄的做用,在什么情况下使用这个函数。
再通俗点说,就是一开始,微软设计让-1作为代表自身进程句柄,但是微软不确定这么做是否妥当,只是暂定下,保不齐以后会改。所以搞了一个函数,这样,万一以后要是修改了因为这个值是从api获取的,所以之前的程序也不会受影响。如果它们直接用的常数-1,那么它们要和未来的windows兼容,就要修改代码重新编译了。不过后来一直都延续下来,谁还会改它呢?
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683179(v=vs.85).aspx
A pseudo handle is a special constant, currently (HANDLE)-1, that is interpreted as the current process handle. For compatibility with future operating systems, it is best to call GetCurrentProcess instead of hard-coding this constant value. The calling process can use a pseudo handle to specify its own process whenever a process handle is required. Pseudo handles are not inherited by child processes.
大概就是说,伪句柄是一个常数,在当前的Windows下,-1被解释成当前进程的句柄,出于操作系统兼容的考虑,你应该用GetCurrentProcess代表当前进程而不是把-1硬编码到你的代码中,当一个调用需要进程句柄的时候,伪句柄可以用来表示它自己的进程,伪句柄不能被子进程继承。