使用CreateProcess()函数
以下是一个使用CreateProcess()函数的例子: $ |" R0 ^+ `4 A5 T& l6 T: W9 Q! | void CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine) {
* K1 Y) x" |* [2 J6 wPROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo;
5 q6 r% R" S& V- _! p1 h% f$ q// Set up members of STARTUPINFO structure. siStartInfo.cb = sizeof(STARTUPINFO); 7 S, W1 j9 K4 h0 I' H. }! l4 P5 X siStartInfo.lpReserved = NULL; siStartInfo.lpReserved2 = NULL; siStartInfo.cbReserved2 = 0;$ n0 }" r6 d( n* p siStartInfo.lpDesktop = NULL; ' w( _5 t* _8 K siStartInfo.dwFlags = 0;
/ Q$ m. M3 h' z V4 t' {// Create the child process.+ Z4 T @9 w2 b: S( a+ G CreateProcess(
NULL,8 {, k- m0 U. N. \: O. ^ strCmdLine.c_str(),: M" x2 P/ x9 ]+ U1 \, E0 J NULL, // process security attributes NULL, // primary thread security attributes- I( Q9 D0 V6 C" _5 N* c 0, // handles are inherited 0, // creation flags8 L! N. ]# n" k: h8 d NULL, // use parent's environment- e0 l, A0 ~: r; j NULL, // use parent's current directory# K+ S, v1 [4 u" X/ L! `' E$ | &siStartInfo, // STARTUPINFO pointer. ?4 e: g4 s1 i( f+ i8 f* J &piProcInfo); // receives PROCESS_INFORMATION
// Wait for the processs to finish DWORD rc = WaitForSingleObject( piProcInfo.hProcess, // process handle INFINITE); }
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |