CreateProcess示例

来源:互联网 发布:java如何转换日期格式 编辑:程序博客网 时间:2024/04/30 09:57
// 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 exitsDWORD 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 handlesCloseHandle(pi.hProcess);CloseHandle(pi.hThread);
0 0
原创粉丝点击