From 04bdc5d11224e786950354b0a724bd92093ad0fd Mon Sep 17 00:00:00 2001 From: Andrew Sampson Date: Sun, 10 Mar 2019 22:42:21 -0700 Subject: [PATCH] Fix #429 --- BorderlessGaming.Logic/Windows/Native.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/BorderlessGaming.Logic/Windows/Native.cs b/BorderlessGaming.Logic/Windows/Native.cs index 36a8dd8..90d956d 100644 --- a/BorderlessGaming.Logic/Windows/Native.cs +++ b/BorderlessGaming.Logic/Windows/Native.cs @@ -217,11 +217,17 @@ public static string GetWindowClassName(IntPtr hWnd) public static string GetWindowTitle(IntPtr hWnd) { // Allocate correct string length first - var length = (int) SendMessage(hWnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero); - var sbWindowTitle = new StringBuilder(length + 1); - SendMessage(hWnd, WM_GETTEXT, (IntPtr) sbWindowTitle.Capacity, sbWindowTitle); - Console.WriteLine(sbWindowTitle.ToString()); - return sbWindowTitle.ToString(); + try + { + var length = (int)SendMessage(hWnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero); + var sbWindowTitle = new StringBuilder(length + 1); + SendMessage(hWnd, WM_GETTEXT, (IntPtr)sbWindowTitle.Capacity, sbWindowTitle); + return sbWindowTitle.ToString(); + } + catch (Exception) + { + return ""; + } } [DllImport("user32.dll", SetLastError = true)]