From 0969fc12cbe3e1850135273497ef65c33be9038d Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Thu, 30 May 2024 22:44:52 +0600 Subject: [PATCH] Fix bitmap creation error in Explorer plugin shell integration --- .../Helper/ShellContextMenuDisplayHelper.cs | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenuDisplayHelper.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenuDisplayHelper.cs index 15c7cb6f0..19414fc71 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenuDisplayHelper.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenuDisplayHelper.cs @@ -285,19 +285,28 @@ public static class ShellContextMenuDisplayHelper private static BitmapSource GetBitmapSourceFromHBitmap(IntPtr hBitmap) { - var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap( - hBitmap, - IntPtr.Zero, - Int32Rect.Empty, - BitmapSizeOptions.FromWidthAndHeight(32, 32) - ); - - if (!DeleteObject(hBitmap)) + try { - throw new Exception("Failed to delete HBitmap."); + var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap( + hBitmap, + IntPtr.Zero, + Int32Rect.Empty, + BitmapSizeOptions.FromWidthAndHeight(32, 32) + ); + + if (!DeleteObject(hBitmap)) + { + throw new Exception("Failed to delete HBitmap."); + } + + return bitmapSource; + } + catch (COMException) + { + // ignore } - return bitmapSource; + return null; } }