利用WaitForInputIdle等待初始化完成CreateProcess

 1  // 函数原型
 2 
 3 BOOL WINAPI CreateProcess(
 4   __in_opt     LPCTSTR lpApplicationName,
 5   __inout_opt  LPTSTR lpCommandLine,
 6   __in_opt     LPSECURITY_ATTRIBUTES lpProcessAttributes,
 7   __in_opt     LPSECURITY_ATTRIBUTES lpThreadAttributes,
 8   __in         BOOL bInheritHandles,
 9   __in         DWORD dwCreationFlags,
10   __in_opt     LPVOID lpEnvironment,
11   __in_opt     LPCTSTR lpCurrentDirectory,
12   __in         LPSTARTUPINFO lpStartupInfo,
13   __out        LPPROCESS_INFORMATION lpProcessInformation
14 );
15 
16  //
17  DWORD WINAPI WaitForInputIdle(
18   __in  HANDLE hProcess,
19   __in  DWORD dwMilliseconds
20 );
21 Return code/value Description 
22  0
23  The wait was satisfied successfully.
24  
25 WAIT_TIMEOUT
26  The wait was terminated because the time- out interval elapsed.
27  
28 WAIT_FAILED
29  An error occurred.
30  
31 
32  //  创建子进程
33          STARTUPINFO startup;
34         PROCESS_INFORMATION procinfo;
35         ::ZeroMemory(&startup,  sizeof(startup));
36         startup.cb =  sizeof(startup);
37         startup.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
38         startup.wShowWindow = SW_HIDE;  //  hidden console window
39          startup.hStdInput = NULL;  //  not used
40          startup.hStdOutput = hPipeOutW;
41         startup.hStdError = hPipeErrW;
42 
43         BOOL started = ::CreateProcess(NULL,         //  command is part of input string
44                          _command,          //  (writeable) command string
45                          NULL,         //  process security
46                          NULL,         //  thread security
47                          TRUE,         //  inherit handles flag
48                          CREATE_SUSPENDED,            //  flags
49                          NULL,         //  inherit environment
50                          _curDir,         //  inherit directory
51                          &startup,     //  STARTUPINFO
52                          &procinfo);   //  PROCESS_INFORMATION
53  if(!started)
54 {
55        error(TEXT( " CreateProcess "), result,  1002);
56 }
57  else
58 {
59         if (WaitForInputIdle(pinfo.hProcess,  30000) ==  0)  
60        {
61               //  ......
62         }
63 }
64 
65              CloseHandle(procinfo.hThread);  
66              CloseHandle(procinfo.hProcess);

转载于:https://www.cnblogs.com/noselhq/archive/2012/11/08/2760374.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值