使用CreateProcess()函数
( j6 x& v- K' r: ^# P" A以下是一个使用CreateProcess()函数的例子: t4 |+ i f/ C6 U6 G C void CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine) {
. b$ g3 M+ M. |2 {$ {- t2 e. ePROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo;
5 Z; g/ t0 G4 }& x// Set up members of STARTUPINFO structure. siStartInfo.cb = sizeof(STARTUPINFO); siStartInfo.lpReserved = NULL; d: P( E- d$ f0 R" G siStartInfo.lpReserved2 = NULL; ( ~! W, p+ u! C2 q siStartInfo.cbReserved2 = 0; siStartInfo.lpDesktop = NULL; siStartInfo.dwFlags = 0;
// Create the child process. CreateProcess(
NULL, strCmdLine.c_str(),& I+ C8 E3 M e! e! @/ B- N. p NULL, // process security attributes) P- n9 ]" K' G- }9 o NULL, // primary thread security attributes7 \# z \+ Q+ a; r4 @2 x6 v1 a. g 0, // handles are inherited 0, // creation flags; c1 m& m* T" `3 s# ^/ | NULL, // use parent's environment! V5 c8 [; C" @7 \" S# Q* D NULL, // use parent's current directory &siStartInfo, // STARTUPINFO pointer& B1 n! `1 I z8 ~4 D3 v. L &piProcInfo); // receives PROCESS_INFORMATION
E( N+ F* p$ _1 a! `// Wait for the processs to finish DWORD rc = WaitForSingleObject( piProcInfo.hProcess, // process handle9 o) S& B, `+ m+ Q INFINITE); }8 d1 g) J6 R% T
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |