fix crash calling GetWindowTextLength()

This commit is contained in:
Kang Yu 2025-02-04 11:01:30 -08:00
parent c719aee32f
commit c15ab870ac

View file

@ -1203,15 +1203,22 @@ namespace PersistentWindows.Common
if (use_cache && windowTitle.ContainsKey(hwnd)) if (use_cache && windowTitle.ContainsKey(hwnd))
return windowTitle[hwnd]; return windowTitle[hwnd];
var length = User32.GetWindowTextLength(hwnd); try
if (length > 0)
{ {
length++; var length = User32.GetWindowTextLength(hwnd);
var title = new StringBuilder(length); if (length > 0)
User32.GetWindowText(hwnd, title, length); {
var t = title.ToString(); length++;
t = t.Trim(); var title = new StringBuilder(length);
return t; User32.GetWindowText(hwnd, title, length);
var t = title.ToString();
t = t.Trim();
return t;
}
}
catch (Exception e)
{
} }
//return hwnd.ToString("X8"); //return hwnd.ToString("X8");