how to suspend the current application
-
In fact Ive called ShellExecute() to execute another application when clicking on the button on the dialog. And I want to suspend the current dialog until the app executed by ShellExecute() finishes its tasks. But I dont know how to do it. Can anyone help? Thanx in advance. PS: I dont know whether WaitForSingleObject() will work.
-
In fact Ive called ShellExecute() to execute another application when clicking on the button on the dialog. And I want to suspend the current dialog until the app executed by ShellExecute() finishes its tasks. But I dont know how to do it. Can anyone help? Thanx in advance. PS: I dont know whether WaitForSingleObject() will work.
If you WaitForSingleObject on the handle of the spawned process the thread doing the waiting will stop until the spawned app completes. To get the process handle it might be an idea to use ShellExecuteEx as you can find out the handle of the spawned process a bit easier. Cheers, Ash
-
In fact Ive called ShellExecute() to execute another application when clicking on the button on the dialog. And I want to suspend the current dialog until the app executed by ShellExecute() finishes its tasks. But I dont know how to do it. Can anyone help? Thanx in advance. PS: I dont know whether WaitForSingleObject() will work.
int RunAppAndWait(char *cmd) // where "cmd" is the command line with args
{
PROCESS_INFORMATION ProcInfo;
STARTUPINFO StartInfo;
int exit_status = 0;memset(&StartInfo, 0, sizeof(StartInfo)); StartInfo.cb = sizeof(StartInfo); if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &StartInfo, &ProcInfo)) { WaitForSingleObject(ProcInfo.hProcess, INFINITE); // wait for the command to finish GetExitCodeProcess(ProcInfo.hProcess, (unsigned long \*)&exit\_status); CloseHandle(ProcInfo.hProcess); CloseHandle(ProcInfo.hThread); return exit\_status; } return 1; // non-zero = failed
}
-
If you WaitForSingleObject on the handle of the spawned process the thread doing the waiting will stop until the spawned app completes. To get the process handle it might be an idea to use ShellExecuteEx as you can find out the handle of the spawned process a bit easier. Cheers, Ash
-
int RunAppAndWait(char *cmd) // where "cmd" is the command line with args
{
PROCESS_INFORMATION ProcInfo;
STARTUPINFO StartInfo;
int exit_status = 0;memset(&StartInfo, 0, sizeof(StartInfo)); StartInfo.cb = sizeof(StartInfo); if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &StartInfo, &ProcInfo)) { WaitForSingleObject(ProcInfo.hProcess, INFINITE); // wait for the command to finish GetExitCodeProcess(ProcInfo.hProcess, (unsigned long \*)&exit\_status); CloseHandle(ProcInfo.hProcess); CloseHandle(ProcInfo.hThread); return exit\_status; } return 1; // non-zero = failed
}