https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e24d3cc952a4fef29151da15466023f2341c4d2a

commit e24d3cc952a4fef29151da15466023f2341c4d2a
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Tue Mar 2 17:50:00 2021 +0900
Commit:     GitHub <[email protected]>
CommitDate: Tue Mar 2 17:50:00 2021 +0900

    [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

Reply via email to