使用CreateProcess()函数7 k/ @6 |' d i
0 }* u( D @7 G* b6 a以下是一个使用CreateProcess()函数的例子: 3 S6 m+ T1 c4 ` j& T& g void CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine) {
2 D0 c4 z3 ], \/ j7 {PROCESS_INFORMATION piProcInfo; ( `1 Y: `6 G1 U STARTUPINFO siStartInfo;
// Set up members of STARTUPINFO structure.& o- Z8 h' @, E( ~% C3 W A siStartInfo.cb = sizeof(STARTUPINFO); siStartInfo.lpReserved = NULL; siStartInfo.lpReserved2 = NULL; 8 X6 D9 o5 t2 M0 M3 r& a, {$ g2 o siStartInfo.cbReserved2 = 0;$ J- q( H/ n& J siStartInfo.lpDesktop = NULL; siStartInfo.dwFlags = 0;
// Create the child process." i c2 w: C+ N8 B) U! f9 o: u CreateProcess(
' Z. N/ K! X) H1 P& o6 `NULL,' Q& P- R2 v2 C" x# }7 e. U# S strCmdLine.c_str(), NULL, // process security attributes NULL, // primary thread security attributes 0, // handles are inherited! ~" V2 T0 C" q 0, // creation flags NULL, // use parent's environment NULL, // use parent's current directory &siStartInfo, // STARTUPINFO pointer# w. g4 O5 ]$ b( x &piProcInfo); // receives PROCESS_INFORMATION
1 ?+ Y7 R2 V+ o// Wait for the processs to finish* ^. {- I. A0 `9 L4 h2 D x6 M DWORD rc = WaitForSingleObject(% l+ W. K" Q$ f2 D8 G piProcInfo.hProcess, // process handle INFINITE); 4 U+ b9 u4 u- f# M% ? }0 i$ g' D1 K9 r6 N O: `1 q
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |