From 36fc962f5c0f2fd33cfd09c816017655104c4201 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 14 Aug 2020 13:27:20 +0200 Subject: [PATCH] kernel32: Use IOCTL_CONDRV_GET_INPUT_INFO in GetConsoleWindow. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/kernel32/console.c | 16 ++++++---------- dlls/kernel32/tests/console.c | 6 ++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c index c38fa5d0c21..032f938a12d 100644 --- a/dlls/kernel32/console.c +++ b/dlls/kernel32/console.c @@ -187,18 +187,14 @@ static BOOL restore_console_mode(HANDLE hin) * Success: hwnd of the console window. * Failure: NULL */ -HWND WINAPI GetConsoleWindow(VOID) +HWND WINAPI GetConsoleWindow(void) { - HWND hWnd = NULL; + struct condrv_input_info info; + BOOL ret; - SERVER_START_REQ(get_console_input_info) - { - req->handle = 0; - if (!wine_server_call_err(req)) hWnd = wine_server_ptr_handle( reply->win ); - } - SERVER_END_REQ; - - return hWnd; + ret = DeviceIoControl( RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle, + IOCTL_CONDRV_GET_INPUT_INFO, NULL, 0, &info, sizeof(info), NULL, NULL ); + return ret ? (HWND)info.win : NULL; } diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c index 1fc23992ba9..1702369d7ae 100644 --- a/dlls/kernel32/tests/console.c +++ b/dlls/kernel32/tests/console.c @@ -3592,6 +3592,7 @@ static void test_FreeConsole(void) WCHAR title[16]; HANDLE handle; DWORD size; + HWND hwnd; UINT cp; BOOL ret; @@ -3646,6 +3647,11 @@ static void test_FreeConsole(void) ok(title[0] == 0xc0c0, "title byffer changed\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "last error %u\n", GetLastError()); + SetLastError(0xdeadbeef); + hwnd = GetConsoleWindow(); + ok(!hwnd, "hwnd = %p\n", hwnd); + ok(GetLastError() == ERROR_INVALID_HANDLE, "last error %u\n", GetLastError()); + if (!skip_nt) { SetStdHandle( STD_INPUT_HANDLE, (HANDLE)0xdeadbeef );