数学建模社区-数学中国

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

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

使用CreateProcess()函数 6 N+ ^" c3 ]$ @. t4 g Q1 G7 P

7 p1 a1 X& `) X. Z; i6 Q8 J' B+ n

以下是一个使用CreateProcess()函数的例子: 9 a, B' S* g4 U# H4 |$ w8 cvoid CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine) 6 j E; q8 R3 J1 `0 X( |* e$ s{

8 d! J; F. e" _3 B7 X1 Q+ T

PROCESS_INFORMATION piProcInfo; 8 w+ G0 o# q0 {5 R' Q- H0 ^ STARTUPINFO siStartInfo;

5 Y, Z! [; P6 `: j, }$ {) v' y( u

// Set up members of STARTUPINFO structure. 4 U. y; O2 i$ b# X& YsiStartInfo.cb = sizeof(STARTUPINFO); ' R8 ?/ E; {, MsiStartInfo.lpReserved = NULL; . w" L% e# a& g8 {siStartInfo.lpReserved2 = NULL; " l, L% v8 l" [' jsiStartInfo.cbReserved2 = 0; % D: I u' [' I6 A8 ^siStartInfo.lpDesktop = NULL; # t, ^# K3 ~- \, {* c" V4 gsiStartInfo.dwFlags = 0;

- i+ H2 S0 ~' b6 K% ~

- D/ G7 V' l) f+ W% s9 f* I7 K // Create the child process. 1 ?! Q! E. m" v2 ECreateProcess(

$ b0 S) T+ s: _

NULL, & i4 ~/ T- Q+ P# h8 v1 N7 S& nstrCmdLine.c_str(), 1 i& k" D# E. i* [; ~2 M7 @$ xNULL, // process security attributes) L j: p4 `; {0 w! \ NULL, // primary thread security attributes 1 a4 r/ r- |" f0, // handles are inherited ! m' `' D; T X2 E$ g, z: M0, // creation flags ' B' z0 ?' o# f, \NULL, // use parent's environment; q, E+ i) C( a# h% o NULL, // use parent's current directory$ W9 d# G7 G& ~3 P &siStartInfo, // STARTUPINFO pointer 8 J# d/ u3 G2 r- {" o1 Y4 A* Z&piProcInfo); // receives PROCESS_INFORMATION

7 C9 m4 t9 i" V& N/ V

// Wait for the processs to finish) z6 l( y& p* J# ?! e DWORD rc = WaitForSingleObject( G# x9 w1 f* x) y6 k/ KpiProcInfo.hProcess, // process handle ' w9 A3 d, t) A+ J T; _- GINFINITE); / a! m- y! c' |0 H, o# s9 [} ( W# E( h* [( Z* H6 o- P/ G 8 P" A* q) O* V. z* @






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