From cd0e949519cce5bda73d661a3bfbec2993bd3724 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Sun, 4 Dec 2022 11:21:44 +0100 Subject: [PATCH] wineconsole: Set launched process name as created console title. wineconsole was setting created console's title to '????\wineconsole.exe'. This was preventing conhost to load its configuration according to first running command path. Signed-off-by: Eric Pouech --- programs/wineconsole/wineconsole.c | 38 ++++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/programs/wineconsole/wineconsole.c b/programs/wineconsole/wineconsole.c index 1924bf791e6..aeeee11aa86 100644 --- a/programs/wineconsole/wineconsole.c +++ b/programs/wineconsole/wineconsole.c @@ -41,36 +41,38 @@ int WINAPI wWinMain( HINSTANCE inst, HINSTANCE prev, WCHAR *cmdline, INT show ) static WCHAR default_cmd[] = L"cmd"; - FreeConsole(); /* make sure we're not connected to inherited console */ - if (!AllocConsole()) - { - ERR( "failed to allocate console: %lu\n", GetLastError() ); - return 1; - } - if (!*cmd) cmd = default_cmd; - startup.dwFlags = STARTF_USESTDHANDLES; - startup.hStdInput = CreateFileW( L"CONIN$", GENERIC_READ | GENERIC_WRITE, 0, NULL, - OPEN_EXISTING, 0, 0 ); - startup.hStdOutput = CreateFileW( L"CONOUT$", GENERIC_READ | GENERIC_WRITE, 0, NULL, - OPEN_EXISTING, 0, 0 ); - startup.hStdError = startup.hStdOutput; - - if (!CreateProcessW( NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info )) + if (!CreateProcessW( NULL, cmd, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &startup, &info )) { + HANDLE hStdInput, hStdOutput; WCHAR format[256], *buf; INPUT_RECORD ir; DWORD len; + exit_code = GetLastError(); - WARN( "CreateProcess failed: %lu\n", exit_code ); + WARN( "CreateProcess '%ls' failed: %lu\n", cmd, exit_code ); + + /* create a new console to display error messages in it */ + FreeConsole(); /* make sure we're not connected to any console */ + if (!AllocConsole()) + { + ERR( "failed to allocate console: %lu\n", GetLastError() ); + return 1; + } + + hStdInput = CreateFileW( L"CONIN$", GENERIC_READ | GENERIC_WRITE, 0, NULL, + OPEN_EXISTING, 0, 0 ); + hStdOutput = CreateFileW( L"CONOUT$", GENERIC_READ | GENERIC_WRITE, 0, NULL, + OPEN_EXISTING, 0, 0 ); + LoadStringW( GetModuleHandleW( NULL ), IDS_CMD_LAUNCH_FAILED, format, ARRAY_SIZE(format) ); len = wcslen( format ) + wcslen( cmd ); if ((buf = malloc( len * sizeof(WCHAR) ))) { swprintf( buf, len, format, cmd ); - WriteConsoleW( startup.hStdOutput, buf, wcslen(buf), &len, NULL); - while (ReadConsoleInputW( startup.hStdInput, &ir, 1, &len ) && ir.EventType == MOUSE_EVENT); + WriteConsoleW( hStdOutput, buf, wcslen(buf), &len, NULL); + while (ReadConsoleInputW( hStdInput, &ir, 1, &len ) && ir.EventType == MOUSE_EVENT); } return exit_code; }