数学建模社区-数学中国

标题: 使用CreateProcess()函数 [打印本页]

作者: 韩冰    时间: 2005-1-26 01:30
标题: 使用CreateProcess()函数

使用CreateProcess()函数 7 z6 P* J) F2 ]9 ^- F6 m v- w+ a/ l

# S- C- S9 @% w& i) h& n

以下是一个使用CreateProcess()函数的例子: $ |" R0 ^+ `4 A5 T& l6 T: W9 Q! | void CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine) $ O0 u' t2 j3 M, y% I{

* K1 Y) x" |* [2 J6 w

PROCESS_INFORMATION piProcInfo; 4 z6 g& L, G) B& A ]' lSTARTUPINFO siStartInfo;

5 q6 r% R" S& V- _! p1 h% f$ q

// Set up members of STARTUPINFO structure. * M) n% K0 _# v0 `6 ^siStartInfo.cb = sizeof(STARTUPINFO); 7 S, W1 j9 K4 h0 I' H. }! l4 P5 X siStartInfo.lpReserved = NULL; 3 X! l1 A. i& T9 osiStartInfo.lpReserved2 = NULL; * ?2 L- O# x- U7 PsiStartInfo.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' {

# m: H/ n+ }8 K2 K3 r// Create the child process.+ Z4 T @9 w2 b: S( a+ G CreateProcess(

+ j8 M) l/ r/ h f" m: Z

NULL,8 {, k- m0 U. N. \: O. ^ strCmdLine.c_str(),: M" x2 P/ x9 ]+ U1 \, E0 J NULL, // process security attributes ' I& b5 {2 p$ l& o0 lNULL, // primary thread security attributes- I( Q9 D0 V6 C" _5 N* c 0, // handles are inherited E( I6 ~% m U4 _* Z# T0, // 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

, @" C9 s) O2 n3 I

// Wait for the processs to finish ' U/ Y I* ~' Q6 c- B4 ]: ~8 \DWORD rc = WaitForSingleObject( 0 E# y5 v3 w6 x' H. E; jpiProcInfo.hProcess, // process handle ) y$ o; k" [1 K2 m2 bINFINITE); 7 P6 P; P- Q5 {) W} 5 j6 o. [& U* |; X 6 c- _5 u! Z& z& a4 a






欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5