kernelbase: Use PEB ConsoleHandle to check for console connection in AllocConsole.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-08-13 16:02:27 +02:00 committed by Alexandre Julliard
parent 43ce429234
commit 1d65e474b1
2 changed files with 4 additions and 5 deletions

View File

@ -150,6 +150,7 @@ static BOOL process_attach( HMODULE module )
if (params->ConsoleHandle == KERNEL32_CONSOLE_ALLOC)
{
HMODULE mod = GetModuleHandleA(0);
params->ConsoleHandle = NULL;
if (RtlImageNtHeader(mod)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
AllocConsole();
}

View File

@ -275,20 +275,18 @@ BOOL WINAPI AllocConsole(void)
STARTUPINFOW app_si, console_si;
WCHAR buffer[1024], cmd[256];
PROCESS_INFORMATION pi;
HANDLE event, std_in, console;
DWORD mode;
HANDLE event, console;
BOOL ret;
TRACE("()\n");
RtlEnterCriticalSection( &console_section );
std_in = CreateFileW( L"CONIN$", GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, 0, NULL, OPEN_EXISTING, 0, 0 );
if (GetConsoleMode( std_in, &mode ))
if (RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle)
{
/* we already have a console opened on this process, don't create a new one */
CloseHandle( std_in );
RtlLeaveCriticalSection( &console_section );
SetLastError( ERROR_ACCESS_DENIED );
return FALSE;
}