// Start the child process
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
TCHAR szCommandLine[] = TEXT("notepad.exe");
if(!CreateProcess(NULL, // No module name (use command line)
szCommandLine, // 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
)
{
AfxMessageBoxFormatted(TEXT("Create process failed: %d"), GetLastError());
return;
}
// Wait until child process exits
DWORD dwResult = WaitForSingleObject(pi.hProcess, INFINITE);
switch (dwResult)
{
case WAIT_FAILED:
AfxMessageBoxFormatted(TEXT("Bad call to function WaitForSingleObject, maybe for invalid handle."));
break;
case WAIT_OBJECT_0:
AfxMessageBoxFormatted(TEXT("Child process exits."));
break;
default:
break;
}
// Close process and thread handles
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CreateProcess示例
最新推荐文章于 2022-12-06 16:06:58 发布