iCAx开思网

标题: CAA中一个流程问题 [打印本页]

作者: cupcake    时间: 2005-8-9 21:27
标题: CAA中一个流程问题
各位高手:
       我的程序要用到一个文本文件,这个文件是别人写的程序生成的,我在用这个程序之前用WinExec
("C:\\ProgramFiles\\intel_a\\caowei\\Debug\\hexinsuanfa.exe",SW_SHOW);来调用别人的程序去产生那个文件,可是别人的这个可执行程序上面有确认对话框(如下图),只有当用户点了那个“展开”按钮之后才开始产生我需要的文本文件,由于我在WinExec语句之后的语句在WinExec执行之后马上开始去读那个文件(这时候文件还没有产生),所以程序报错,请问有什么办法可以使文本文件产生后WinExec之后的代码才开始执行。
作者: xyzhu    时间: 2005-8-10 15:34
你可以用CreateProcess, 然后用WaitForSingleObject等待"hexinsuanfa.exe"结束.
(https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp 里有说明和例子)
作者: cupcake    时间: 2005-8-10 20:06
谢谢你了
我试试看
:)
作者: cupcake    时间: 2005-8-10 21:18
我看过了
请问CreateProcess,成功后,怎样WaitForSingleObject等待那个exe结束?代码怎样写呢?
作者: cupcake    时间: 2005-8-10 21:30
STARTUPINFO si;
  &nbspROCESS_INFORMATION pi;
  
   ZeroMemory( [$si, sizeof(si) )]
   si.cb = sizeof(si);
   ZeroMemory( [$pi, sizeof(pi) )]
   
   // Start the child process.  
  int proFlag= CreateProcess( NULL,   // No module name (use command line).  
     TEXT("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.
   
  if(proFlag==0)     
   {
     printf( "CreateProcess failed (%d).\n", GetLastError() );
   }
  else
  {
  WinExec("C:\\Program Files\\intel_a\\caowei\\Debug\\hexinsuanfa.exe",SW_SHOW);
  }
  
现在是这样,应该怎么改呢?
:)
作者: cupcake    时间: 2005-8-10 21:33
提示说CreateProcess failed(2)
为什么?
作者: xyzhu    时间: 2005-8-10 21:43
STARTUPINFO si;
  &nbspROCESS_INFORMATION pi;
  
   ZeroMemory( [$si, sizeof(si) )]
   si.cb = sizeof(si);
   ZeroMemory( π, sizeof(pi) );
   
   // Start the child process.
  int proFlag= CreateProcess( NULL, // No module name (use command line).
  
// !!!!!
   TEXT("C:\\Program Files\\intel_a\\caowei\\Debug\\hexinsuanfa.exe"), // 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.
   π ); // Pointer to PROCESS_INFORMATION structure.
  
  if(proFlag==0)
   {
   printf( "CreateProcess failed (%d).\n", GetLastError() );
   return;
   }  
  
   // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );
  
   // Close process and thread handles.  
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
  
   // now the file shall exist
   // your code ...
作者: cupcake    时间: 2005-8-11 16:00
谢谢高手,可以了。
:)




欢迎光临 iCAx开思网 (https://www.icax.org/) Powered by Discuz! X3.3