From e24d3cc952a4fef29151da15466023f2341c4d2a Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Tue, 2 Mar 2021 17:50:00 +0900 Subject: [PATCH] [SDK][ATL] Fix CWindow::GetWindowText method of BSTR (#3498) - Fix generic text mapping for GetWindowText and GetWindowTextLength functions. - Fix the position. - Fix the length. - Fail elegantly if necessary. CORE-9281 --- sdk/lib/atl/atlwin.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sdk/lib/atl/atlwin.h b/sdk/lib/atl/atlwin.h index d8994988d40..2df36b612ee 100644 --- a/sdk/lib/atl/atlwin.h +++ b/sdk/lib/atl/atlwin.h @@ -782,11 +782,14 @@ public: BOOL GetWindowText(BSTR& bstrText) { ATLASSERT(::IsWindow(m_hWnd)); - int length = ::GetWindowTextLength(m_hWnd); - if (!SysReAllocStringLen(&bstrText, NULL, length)) + INT length = ::GetWindowTextLengthW(m_hWnd); + if (!::SysReAllocStringLen(&bstrText, NULL, length)) return FALSE; - ::GetWindowText(m_hWnd, (LPTSTR)&bstrText[2], length); - return TRUE; + if (::GetWindowTextW(m_hWnd, bstrText, length + 1)) + return TRUE; + ::SysFreeString(bstrText); + bstrText = NULL; + return FALSE; } int GetWindowTextLength() const