From a8f2f5846687ece77ff8005fb913512112ff0931 Mon Sep 17 00:00:00 2001 From: Arvind Shyamsundar Date: Fri, 21 Jun 2024 16:56:07 -0700 Subject: [PATCH] Call SymSetParentWindow to ensure modal UI In some cases, dbghelp / symsrv may pop up UI dialogs, such as to authenticate to a symbol server. We want those dialogs to be modal so that they are clearly visible to the user. Calling SymSetParentWindow ensures the modal nature of such possible UI elements. --- Engine/SafeNativeMethods.cs | 2 ++ Engine/SymSrvHelpers.cs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Engine/SafeNativeMethods.cs b/Engine/SafeNativeMethods.cs index c847acf..efbe7c4 100644 --- a/Engine/SafeNativeMethods.cs +++ b/Engine/SafeNativeMethods.cs @@ -62,5 +62,7 @@ internal static bool EstablishActivationContext() { [DllImport("dbghelp.dll")] public static extern bool SymCleanup(IntPtr hProcess); [DllImport("dbghelp.dll", CharSet = CharSet.Unicode)] public static extern bool SymInitialize(IntPtr hProcess, [MarshalAs(UnmanagedType.LPWStr)] string UserSearchPath, bool fInvadeProcess); + + [DllImport("dbghelp.dll")] public static extern bool SymSetParentWindow(IntPtr hWnd); } } diff --git a/Engine/SymSrvHelpers.cs b/Engine/SymSrvHelpers.cs index b9b77ec..4377867 100644 --- a/Engine/SymSrvHelpers.cs +++ b/Engine/SymSrvHelpers.cs @@ -22,6 +22,9 @@ public static List GetFolderPathsForPDBs(StackResolver parent, string sy var retval = new List(); Contract.Requires(null != syms); Contract.Requires(null != parent); + + if (!SafeNativeMethods.SymSetParentWindow(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle)) return retval; + if (!SafeNativeMethods.SymInitialize((IntPtr)(-1), symPath, false)) return retval; int progress = 0; foreach (var sym in syms) {