Skip to content

Commit

Permalink
Merge pull request #45 from leoafarias/fix/spawn_window_process
Browse files Browse the repository at this point in the history
Added conditional for process
  • Loading branch information
leoafarias authored Apr 14, 2021
2 parents b9df656 + 539261d commit 3ea19ca
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,27 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
{
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent())
{
CreateAndAttachConsole();
// TODO: Remove conditional https://github.com/flutter/flutter/issues/47891
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
CreateAndAttachConsole();
} else {
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;

PROCESS_INFORMATION pi = { 0 };
WCHAR lpszCmd[MAX_PATH] = L"cmd.exe";
if (::CreateProcess(NULL, lpszCmd, NULL, NULL, FALSE, CREATE_NEW_CONSOLE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
do {
if (::AttachConsole(pi.dwProcessId)) {
::TerminateProcess(pi.hProcess, 0);
break;
}
} while (ERROR_INVALID_HANDLE == GetLastError());
::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);
}
}

// Initialize COM, so that it is available for use in the library and/or
Expand Down

0 comments on commit 3ea19ca

Please sign in to comment.