WaitForSingleObject这个函数怎么用?
我的程序是这样写的:
if( !CreateProcess( NULL, // No module name (use command line)
cmd.GetBuffer(0), // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d)\n", GetLastError() );
return 0;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
在我的程序里面,创建了一个进程,该进程启动ie。当ie关闭时,我的程序也结束。
这段程序在我的win7系统下,有问题。如果我事先将ie启动起来,再运行我的程序,
这时虽然也启动起了一个ie,但WaitForSingleObject函数却上来就得到了信号,然后
我的程序就结束了。
请问,这是怎么回事呢?