From a75d9436bc68a3a657f5bf216b816480c430bdc8 Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Mon, 16 Jul 2018 13:41:32 +0200 Subject: [PATCH] Fix potential issue with Unicode Fix potential compilation error C2664: 'HANDLE CreateFileW(LPCWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE)': cannot convert argument 1 from 'const char [8]' to 'LPCWSTR' with Unicode/MBCS, as reported here: https://github.com/root-project/cling/issues/186#issuecomment-404902026 --- lib/UserInterface/textinput/TerminalDisplayWin.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/UserInterface/textinput/TerminalDisplayWin.cpp b/lib/UserInterface/textinput/TerminalDisplayWin.cpp index c44333bd..6455b4d0 100644 --- a/lib/UserInterface/textinput/TerminalDisplayWin.cpp +++ b/lib/UserInterface/textinput/TerminalDisplayWin.cpp @@ -19,6 +19,12 @@ #include +#ifdef UNICODE +#define filename L"CONOUT$" +#else +#define filename "CONOUT$" +#endif + namespace textinput { TerminalDisplayWin::TerminalDisplayWin(): TerminalDisplay(false), fStartLine(0), fIsAttached(false), @@ -31,7 +37,7 @@ namespace textinput { if (!isConsole) { // Prevent redirection from stealing our console handle, // simply open our own. - fOut = ::CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, + fOut = ::CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); ::GetConsoleMode(fOut, &fOldMode); @@ -48,6 +54,8 @@ namespace textinput { HandleResizeEvent(); } +#undef filename + TerminalDisplayWin::~TerminalDisplayWin() { if (fDefaultAttributes) { ::SetConsoleTextAttribute(fOut, fDefaultAttributes);