process(windows): fallback to GenerateConsoleCtrlEvent and TerminateProcess if necessary
This commit is contained in:
@@ -520,12 +520,12 @@ done:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL CALLBACK terminate_app(HWND hwnd, LPARAM proc_id)
|
static BOOL CALLBACK terminate_app(HWND hwnd, LPARAM lparam)
|
||||||
{
|
{
|
||||||
DWORD current_proc_id = 0;
|
DWORD current_proc_id = 0, *term_info = (DWORD *) lparam;
|
||||||
GetWindowThreadProcessId(hwnd, ¤t_proc_id);
|
GetWindowThreadProcessId(hwnd, ¤t_proc_id);
|
||||||
if (current_proc_id == (DWORD) proc_id) {
|
if (current_proc_id == term_info[0] && PostMessage(hwnd, WM_CLOSE, 0, 0)) {
|
||||||
PostMessage(hwnd, WM_CLOSE, 0, 0);
|
term_info[1]++;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -533,10 +533,18 @@ static BOOL CALLBACK terminate_app(HWND hwnd, LPARAM proc_id)
|
|||||||
bool SDL_SYS_KillProcess(SDL_Process *process, bool force)
|
bool SDL_SYS_KillProcess(SDL_Process *process, bool force)
|
||||||
{
|
{
|
||||||
if (!force) {
|
if (!force) {
|
||||||
EnumWindows(terminate_app, (LPARAM) process->internal->process_information.dwProcessId);
|
// term_info[0] is the process ID, term_info[1] is number of successful tries
|
||||||
PostThreadMessage(process->internal->process_information.dwThreadId, WM_CLOSE, 0, 0);
|
DWORD term_info[2];
|
||||||
|
term_info[0] = process->internal->process_information.dwProcessId;
|
||||||
|
term_info[1] = 0;
|
||||||
|
EnumWindows(terminate_app, (LPARAM) &term_info);
|
||||||
|
if (term_info[1] || PostThreadMessage(process->internal->process_information.dwThreadId, WM_CLOSE, 0, 0)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, term_info[0])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!TerminateProcess(process->internal->process_information.hProcess, 1)) {
|
if (!TerminateProcess(process->internal->process_information.hProcess, 1)) {
|
||||||
return WIN_SetError("TerminateProcess failed");
|
return WIN_SetError("TerminateProcess failed");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user