5-8万年薪顶级嵌入式,京沪深就业地 浅谈并行编程中的任务分解模式
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  进程/线程/DLL

100分的问题,急!!!(关于多线程)

楼主cmu()2002-05-29 14:34:49 在 VC/MFC / 进程/线程/DLL 提问

请问:  
  如何等待   用ShellExecute   或   CreateProcess   制造的线程结束?  
   
  用省么样的wait   function?  
  高手能不能给个小例子?  
   
  多谢了! 问题点数:100、回复次数:5Top

1 楼acptvc(微软全球技术中心 VC技术支持)回复于 2002-05-29 15:54:32 得分 70

CreateProcess函数的原型如下所示:  
  BOOL   CreateProcess(  
      LPCTSTR   lpApplicationName,                                   //   name   of   executable   module  
      LPTSTR   lpCommandLine,                                             //   command   line   string  
      LPSECURITY_ATTRIBUTES   lpProcessAttributes,   //   SD  
      LPSECURITY_ATTRIBUTES   lpThreadAttributes,     //   SD  
      BOOL   bInheritHandles,                                             //   handle   inheritance   option  
      DWORD   dwCreationFlags,                                           //   creation   flags  
      LPVOID   lpEnvironment,                                             //   new   environment   block  
      LPCTSTR   lpCurrentDirectory,                                 //   current   directory   name  
      LPSTARTUPINFO   lpStartupInfo,                               //   startup   information  
      LPPROCESS_INFORMATION   lpProcessInformation   //   process   information  
  );  
   
  其中最后一个参数的结构体如下所示:  
  typedef   struct   _PROCESS_INFORMATION   {    
          HANDLE   hProcess;    
          HANDLE   hThread;    
          DWORD   dwProcessId;    
          DWORD   dwThreadId;    
  }   PROCESS_INFORMATION;    
   
  调用CreateProcess创建一个新进程时,该参数保存了该进程的信息(进程的句柄和ID等),应用程序可以通过这些信息来通信或者控制。下面是一个MSDN中的小例子,希望能对您有所帮助。  
   
  void   main(   VOID   )  
  {  
          STARTUPINFO   si;  
          PROCESS_INFORMATION   pi;  
   
          ZeroMemory(   &si,   sizeof(si)   );  
          si.cb   =   sizeof(si);  
          ZeroMemory(   &pi,   sizeof(pi)   );  
   
          //   创建子进程  
          if(   !CreateProcess(   NULL,   //   No   module   name   (use   command   line).    
                  "MyChildProcess",   //   Command   line.    
                  NULL,                           //   Process   handle   not   inheritable.    
                  NULL,                           //   Thread   handle   not   inheritable.    
                  FALSE,                         //   Set   handle   inheritance   to   FALSE.    
                  0,                                 //   No   creation   flags.    
                  NULL,                           //   Use   parent's   environment   block.    
                  NULL,                           //   Use   parent's   starting   directory.    
                  &si,                             //   Pointer   to   STARTUPINFO   structure.  
                  &pi   )                           //   Pointer   to   PROCESS_INFORMATION   structure.  
          )    
          {  
                  ErrorExit(   "CreateProcess   failed."   );  
          }  
   
          //   等待子进程退出  
          WaitForSingleObject(   pi.hProcess,   INFINITE   );  
   
          //   关闭句柄  
          CloseHandle(   pi.hProcess   );  
          CloseHandle(   pi.hThread   );  
  }  
     
   
  -   微软全球技术中心   VC技术支持  
   
  本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款  
  (http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。  
   
  为了为您创建更好的讨论环境,请参加我们的用户满意度调查  
  (http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。  
  Top

2 楼westlingsnow(西泠雪)回复于 2002-05-29 16:05:20 得分 0

upTop

3 楼xuying()回复于 2002-05-29 16:12:05 得分 0

同意   acptvc(微软全球技术中心   VC技术支持)    
   
  不过需要注意的是:ShellExecute   或   CreateProcess   创建的是进程,而非线程。Top

4 楼southnan(就这么着)回复于 2002-05-29 16:19:06 得分 30

你这个是多进程的问题啊,我看题目还以为是多线程呢。  
   
   
  DWORD   WaitForSingleObject(  
      HANDLE   hHandle,                 //   handle   to   object  
      DWORD   dwMilliseconds       //   time-out   interval  
  );  
  ---hHandle    
  [in]   Handle   to   the   object.   For   a   list   of   the   object   types   whose   handles   can   be   specified,   see   the   following   Remarks   section.    
  If   this   handle   is   closed   while   the   wait   is   still   pending,   the   function's   behavior   is   undefined  
  --dwMilliseconds    
  [in]   Specifies   the   time-out   interval,   in   milliseconds.   The   function   returns   if   the   interval   elapses,   even   if   the   object's   state   is   nonsignaled.   If   dwMilliseconds   is   zero,   the   function   tests   the   object's   state   and   returns   immediately.   If   dwMilliseconds   is   INFINITE,   the   function's   time-out   interval   never   elapses  
   
  Top

5 楼cmu()回复于 2002-05-30 01:21:08 得分 0

多谢大家!  
  有没有用ShellExecute的例子?  
  Top

相关问题

  • 关于多线程通讯。急急急!!!
  • 关于多线程,急急急!
  • 急,Linux下的多线程编程
  • 谁有多线程的例子? 急
  • help:多线程同步(急!给分100)
  • 一个多线程的问题?急!!!!!!!!!!
  • 多线程同步问题(急)
  • 紧急求助java多线程编程!!!!!!!!!!!!!
  • 急需关于多线程的资料;
  • ★★★★★紧急求助,多线程的问题★★★★★

关键词

  • null
  • createprocess
  • 进程
  • dwmilliseconds
  • si
  • handle
  • shellexecute
  • pi
  • 创建
  • hprocess

得分解答快速导航

  • 帖主:cmu
  • acptvc
  • southnan

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
x 提问