数学建模社区-数学中国

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

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

使用CreateProcess()函数 6 k9 o; Y! Y. a H8 k$ S- ^/ ^. \

( j6 x& v- K' r: ^# P" A

以下是一个使用CreateProcess()函数的例子: t4 |+ i f/ C6 U6 G C void CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine) 6 F ^% D! H. x{

. b$ g3 M+ M. |2 {$ {- t2 e. e

PROCESS_INFORMATION piProcInfo; G. l1 \* w# M$ t% cSTARTUPINFO siStartInfo;

5 Z; g/ t0 G4 }& x

// Set up members of STARTUPINFO structure. 7 Z6 W5 u+ w, w8 J8 V# PsiStartInfo.cb = sizeof(STARTUPINFO); : A4 U$ o s% k; N! IsiStartInfo.lpReserved = NULL; d: P( E- d$ f0 R" G siStartInfo.lpReserved2 = NULL; ( ~! W, p+ u! C2 q siStartInfo.cbReserved2 = 0; ; u/ I0 w, y- A; j5 usiStartInfo.lpDesktop = NULL; ' T: H6 l. s8 q2 t% UsiStartInfo.dwFlags = 0;

8 w" w* f$ M% ?- Z" `; B

8 Z9 C* k1 ?% l* ]. E2 ?0 V// Create the child process. . |4 t: ~6 U) _7 tCreateProcess(

1 I$ |5 O9 V8 ]) O/ G: {

NULL, 6 m" x R' s& u! N+ WstrCmdLine.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 : Y% _9 ^- b2 M8 ^# C; m) d5 C0, // 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 " M% Q y8 m* c* e. y2 b&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 ' r7 c [& g6 o% Q& J8 | hDWORD rc = WaitForSingleObject( 3 O [5 U! m* g3 F- j& FpiProcInfo.hProcess, // process handle9 o) S& B, `+ m+ Q INFINITE); # k/ I" E2 F" R- L1 \}8 d1 g) J6 R% T . V1 d9 l; [: o: W& p+ Y






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