mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
only stackalloc the getwindowtitle buffer when length is small.
This commit is contained in:
parent
02a45661c4
commit
9350e82b77
1 changed files with 2 additions and 2 deletions
|
|
@ -54,12 +54,12 @@ namespace Flow.Launcher.Plugin.SharedCommands
|
|||
{
|
||||
var capacity = PInvoke.GetWindowTextLength(hwnd) + 1;
|
||||
int length;
|
||||
Span<char> buffer = stackalloc char[capacity];
|
||||
Span<char> buffer = capacity < 1024 ? stackalloc char[capacity] : new char[capacity];
|
||||
fixed (char* pBuffer = buffer)
|
||||
{
|
||||
// If the window has no title bar or text, if the title bar is empty,
|
||||
// or if the window or control handle is invalid, the return value is zero.
|
||||
length = PInvoke.GetWindowText(hwnd, (PWSTR)pBuffer, capacity);
|
||||
length = PInvoke.GetWindowText(hwnd, pBuffer, capacity);
|
||||
}
|
||||
|
||||
return buffer[..length].ToString();
|
||||
|
|
|
|||
Loading…
Reference in a new issue