From c308dfcad75d7b491ea88d39118fb8aee70d6b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ku=C4=8Dera?= <10546952+miloush@users.noreply.github.com> Date: Mon, 4 Jul 2022 12:52:27 +0100 Subject: [PATCH] Ignore NotImplementedException from ITaskbarList (#6547) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan Kučera --- .../MS/Internal/AppModel/ShellProvider.cs | 3 ++- .../System/Windows/Window.cs | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ShellProvider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ShellProvider.cs index 77be9f5aa..fc75ec3c9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ShellProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ShellProvider.cs @@ -697,7 +697,8 @@ internal interface ITaskbarList /// /// This function must be called first to validate use of other members. /// - void HrInit(); + [PreserveSig] + HRESULT HrInit(); /// /// This function adds a tab for hwnd to the taskbar. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs index 26177c8a9..1ce83b3b5 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs @@ -637,7 +637,7 @@ private void HandleTaskbarListError(HRESULT hr) // Explorer being non-responsive should be a transient issue. Post back to apply the full TaskbarItemInfo. _taskbarRetryTimer.Start(); } - else if (hr == (HRESULT)Win32Error.ERROR_INVALID_WINDOW_HANDLE) + else if (hr == (HRESULT)Win32Error.ERROR_INVALID_WINDOW_HANDLE || hr == HRESULT.E_NOTIMPL) { // We'll get this when Explorer's not running. This means there's no Shell to integrate with. if (TraceShell.IsEnabled) @@ -6292,6 +6292,7 @@ private void ApplyTaskbarItemInfo() return; } + HRESULT hr = HRESULT.S_OK; if (_taskbarList == null) { // If we don't have a handle and there isn't a TaskbarItemInfo, then we don't have anything to apply or remove. @@ -6304,12 +6305,19 @@ private void ApplyTaskbarItemInfo() try { taskbarList = (ITaskbarList)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID.TaskbarList))); - taskbarList.HrInit(); + + hr = taskbarList.HrInit(); + if (hr != HRESULT.S_OK) + { + // Taskbar not available (no user logged in, running under terminal service, custom shell, etc.) + HandleTaskbarListError(hr); + return; + } // This QI will only work on Win7. _taskbarList = (ITaskbarList3)taskbarList; taskbarList = null; -} + } finally { Utilities.SafeRelease(ref taskbarList); @@ -6334,7 +6342,6 @@ private void ApplyTaskbarItemInfo() } // Apply (or clear) all aspects of the TaskbarItemInfo to this Window. - HRESULT hr = HRESULT.S_OK; hr = RegisterTaskbarThumbButtons(); if (hr.Succeeded) -- GitLab