很多和获取handle有关的api(如OpenXXXX之类)都会有bInheritHandles的flag,可是inherited handle到底有什么用处,应该怎么用呢?比如CreateProcess,如果bInheritHandles给TRUE的话,传说子进程可以继承父进程的handle,可是这些handle怎么访问呢?这个问题google了很久都没搞明白,请明白的出来解释下,或者给个reference也行。
解决方案 »
- 如何从txt文件中读取数据到程序的数组中?
- MFC-命令分派
- 高分求助:多国语言显示的问题
- 请问如何使toolbar的按钮按下后再抬起不保持凹陷状态?
- 一个VC++6.0的问题
- 请问调用window api的编译设置问题?
- 程序集成(关于多文档视图切换的问题)
- 非常的复杂,高高手看看,不会不要乱答啊。
- CDockablePane 怎么取消标题栏的倒三角按钮
- 高分求教:有什么方法可以直接将pdf 文件转换为word文档???
- 你见过CListCtrl吗?我彻底解决了CListCtrl的闪烁问题,但有个问题很困扰我,不明白是为什么.肯请务必指教.还有强烈要求版主加金...加鑫
- 快春节了,大家陆续回家了,散分!祝大家春节快乐!
比方说在管道通信中,父进程定义了管道通信句柄,如果bInheritHandles给TRUE,子进程那个就可以利用管道通信句柄进行通信
子进程又怎么知道每个handle是什么?还有最关键的,子进程里面用这些handle的代码怎么写?
比如父进程 HANDLE handle = OpenXXXX(....);
父进程里用到的时候就可以UseHandle(handle);
子进程里要用到的时候 UseHandle(????);这个参数怎么抓到?
By far, the most common way for a child process to determine the handle value of the kernel object that it's expecting is to have the handle value passed as a command-line argument to the child process. The child process' initialization code parses the command line (usually by calling _stscanf_s) and extracts the handle value. Once the child has the handle value, it has the same access to the object as its parent. Note that the only reason handle inheritance works is because the handle value of the shared kernel object is identical in both the parent process and the child process. This is why the parent process is able to pass the handle value as a command-line argument.
Of course, you can use other forms of interprocess communication to transfer an inherited kernel object handle value from the parent process into the child process. One technique is for the parent to wait for the child to complete initialization (using the WaitForInputIdle function discussed in Chapter 9, "Thread Synchronization with Kernel Objects"); then the parent can send or post a message to a window created by a thread in the child process.Another technique is for the parent process to add an environment variable to its environment block. The variable's name would be something that the child process knows to look for, and the variable's value would be the handle value of the kernel object to be inherited. Then when the parent spawns the child process, the child process inherits the parent's environment variables and can easily call GetEnvironmentVariable to obtain the inherited object's handle value. This approach is excellent if the child process is going to spawn another child process, because the environment variables can be inherited again. The special case of a child process inheriting its parent console is detailed in the Microsoft Knowledge Base at http://support.microsoft.com/kb/190351.1> 传递命令行
2> 子进程初始化完后, 发送消息
3> 环境变量