使用CreateProcess()函数
7 p1 a1 X& `) X. Z; i6 Q8 J' B+ n以下是一个使用CreateProcess()函数的例子:
8 d! J; F. e" _3 B7 X1 Q+ T void CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine) {PROCESS_INFORMATION piProcInfo; 8 w+ G0 o# q0 {5 R' Q- H0 ^ STARTUPINFO siStartInfo;
// Set up members of STARTUPINFO structure.
- i+ H2 S0 ~' b6 K% ~ siStartInfo.cb = sizeof(STARTUPINFO); siStartInfo.lpReserved = NULL; siStartInfo.lpReserved2 = NULL; siStartInfo.cbReserved2 = 0; siStartInfo.lpDesktop = NULL; siStartInfo.dwFlags = 0;- D/ G7 V' l) f+ W% s9 f* I7 K // Create the child process.
$ b0 S) T+ s: _ CreateProcess(NULL,
strCmdLine.c_str(), NULL, // process security attributes) L j: p4 `; {0 w! \ NULL, // primary thread security attributes 0, // handles are inherited 0, // creation flags NULL, // use parent's environment; q, E+ i) C( a# h% o NULL, // use parent's current directory$ W9 d# G7 G& ~3 P &siStartInfo, // STARTUPINFO pointer &piProcInfo); // receives PROCESS_INFORMATION// Wait for the processs to finish) z6 l( y& p* J# ?! e DWORD rc = WaitForSingleObject(
piProcInfo.hProcess, // process handle INFINITE); } 8 P" A* q) O* V. z* @欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |