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 );