From dab8c96fa86d4126773a95d420f9138fee83d126 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 7 May 2015 22:56:02 -0300 Subject: [PATCH] Fix bug getting ANSI clipboard text on Windows Sometimes the clipboard content is in CF_TEXT format and there is no implicit CF_UNICODETEXT conversion. --- src/she/win/clipboard.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/she/win/clipboard.cpp b/src/she/win/clipboard.cpp index 9d0449aca..0e105cb61 100644 --- a/src/she/win/clipboard.cpp +++ b/src/she/win/clipboard.cpp @@ -42,9 +42,9 @@ std::string ClipboardWin32::getText(DisplayHandle hwnd) if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { if (open_clipboard((HWND)hwnd)) { HGLOBAL hglobal = GetClipboardData(CF_UNICODETEXT); - if (hglobal != NULL) { + if (hglobal) { LPWSTR lpstr = static_cast(GlobalLock(hglobal)); - if (lpstr != NULL) { + if (lpstr) { text = base::to_utf8(lpstr).c_str(); GlobalUnlock(hglobal); } @@ -52,6 +52,19 @@ std::string ClipboardWin32::getText(DisplayHandle hwnd) CloseClipboard(); } } + else if (IsClipboardFormatAvailable(CF_TEXT)) { + if (open_clipboard((HWND)hwnd)) { + HGLOBAL hglobal = GetClipboardData(CF_TEXT); + if (hglobal) { + LPSTR lpstr = static_cast(GlobalLock(hglobal)); + if (lpstr) { + text = lpstr; + GlobalUnlock(hglobal); + } + } + CloseClipboard(); + } + } return text; }