数学建模社区-数学中国

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

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

使用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) # z5 C- ]# |5 l{

2 D0 c4 z3 ], \/ j7 {

PROCESS_INFORMATION piProcInfo; ( `1 Y: `6 G1 U STARTUPINFO siStartInfo;

S: J! c4 R' N0 G

// Set up members of STARTUPINFO structure.& o- Z8 h' @, E( ~% C3 W A siStartInfo.cb = sizeof(STARTUPINFO); 1 T5 ?9 x# T( K, dsiStartInfo.lpReserved = NULL; 1 D" O w. x* s3 O6 YsiStartInfo.lpReserved2 = NULL; 8 X6 D9 o5 t2 M0 M3 r& a, {$ g2 o siStartInfo.cbReserved2 = 0;$ J- q( H/ n& J siStartInfo.lpDesktop = NULL; ! }4 q8 q$ ~: ] |" P- V: CsiStartInfo.dwFlags = 0;

- C& T* e! N' h+ l6 ~

: I% Z) T/ i' s// 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(), ! }- d' e( O) p% j3 R' |5 mNULL, // process security attributes : e* \- H" I# C6 d2 q# \NULL, // primary thread security attributes ' O1 m# c/ i) Z0 t% Z0, // handles are inherited! ~" V2 T0 C" q 0, // creation flags : U0 s/ v$ R; B3 x8 KNULL, // use parent's environment ; a( E; M1 j2 B: Y: cNULL, // use parent's current directory ; P" f2 D$ y6 b; z&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 7 @6 e3 n, i6 m" y |INFINITE); 4 U+ b9 u4 u- f# M% ? }0 i$ g' D1 K9 r6 N O: `1 q - j6 p# p# N; |: A






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