From 9716814879dc19643663f8951d8ad1d681fd1cae Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Sat, 23 Dec 2017 23:56:04 +0100 Subject: [PATCH] =?UTF-8?q?[NTVDM]=20Deduplicate=20IsConsoleHandle()=20usi?= =?UTF-8?q?ng=20the=20correct=20version=20pointed=20by=20Herm=C3=A8s.=20#1?= =?UTF-8?q?79?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- subsystems/mvdm/ntvdm/console/console.c | 24 ++++++++++++++++++++++++ subsystems/mvdm/ntvdm/console/video.c | 24 ------------------------ subsystems/mvdm/ntvdm/ntvdm.h | 1 + 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/subsystems/mvdm/ntvdm/console/console.c b/subsystems/mvdm/ntvdm/console/console.c index 72200a103a2..db2a4682735 100644 --- a/subsystems/mvdm/ntvdm/console/console.c +++ b/subsystems/mvdm/ntvdm/console/console.c @@ -500,6 +500,30 @@ ConsoleCleanup(VOID) if (ConsoleInput != INVALID_HANDLE_VALUE) CloseHandle(ConsoleInput); } +BOOL IsConsoleHandle(HANDLE hHandle) +{ + DWORD dwMode; + + /* Check whether the handle may be that of a console... */ + if ((GetFileType(hHandle) & ~FILE_TYPE_REMOTE) != FILE_TYPE_CHAR) + return FALSE; + + /* + * It may be. Perform another test... The idea comes from the + * MSDN description of the WriteConsole API: + * + * "WriteConsole fails if it is used with a standard handle + * that is redirected to a file. If an application processes + * multilingual output that can be redirected, determine whether + * the output handle is a console handle (one method is to call + * the GetConsoleMode function and check whether it succeeds). + * If the handle is a console handle, call WriteConsole. If the + * handle is not a console handle, the output is redirected and + * you should call WriteFile to perform the I/O." + */ + return GetConsoleMode(hHandle, &dwMode); +} + VOID MenuEventHandler(PMENU_EVENT_RECORD MenuEvent) { switch (MenuEvent->dwCommandId) diff --git a/subsystems/mvdm/ntvdm/console/video.c b/subsystems/mvdm/ntvdm/console/video.c index de2910c90df..d19841b7f25 100644 --- a/subsystems/mvdm/ntvdm/console/video.c +++ b/subsystems/mvdm/ntvdm/console/video.c @@ -436,30 +436,6 @@ static VOID DetachFromConsoleInternal(VOID) TextFramebuffer = NULL; } -static BOOL IsConsoleHandle(HANDLE hHandle) -{ - DWORD dwMode; - - /* Check whether the handle may be that of a console... */ - if ((GetFileType(hHandle) & ~FILE_TYPE_REMOTE) != FILE_TYPE_CHAR) - return FALSE; - - /* - * It may be. Perform another test... The idea comes from the - * MSDN description of the WriteConsole API: - * - * "WriteConsole fails if it is used with a standard handle - * that is redirected to a file. If an application processes - * multilingual output that can be redirected, determine whether - * the output handle is a console handle (one method is to call - * the GetConsoleMode function and check whether it succeeds). - * If the handle is a console handle, call WriteConsole. If the - * handle is not a console handle, the output is redirected and - * you should call WriteFile to perform the I/O." - */ - return GetConsoleMode(hHandle, &dwMode); -} - static VOID SetActiveScreenBuffer(HANDLE ScreenBuffer) { ASSERT(ScreenBuffer); diff --git a/subsystems/mvdm/ntvdm/ntvdm.h b/subsystems/mvdm/ntvdm/ntvdm.h index 616cc70aac6..60a763fd15a 100644 --- a/subsystems/mvdm/ntvdm/ntvdm.h +++ b/subsystems/mvdm/ntvdm/ntvdm.h @@ -103,6 +103,7 @@ UpdateVdmMenuDisks(VOID); BOOL ConsoleAttach(VOID); VOID ConsoleDetach(VOID); VOID ConsoleReattach(HANDLE ConOutHandle); +BOOL IsConsoleHandle(HANDLE hHandle); VOID MenuEventHandler(PMENU_EVENT_RECORD MenuEvent); VOID FocusEventHandler(PFOCUS_EVENT_RECORD FocusEvent);