[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
This commit is contained in:
Katayama Hirofumi MZ 2021-03-02 17:50:00 +09:00 committed by GitHub
parent 6de330026c
commit e24d3cc952
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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