diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Utils/Native.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Utils/Native.cs index edf3c062dc..5a4b480b6c 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Utils/Native.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Utils/Native.cs @@ -140,7 +140,7 @@ public sealed partial class Native void GetParent(out IShellItem ppsi); - void GetDisplayName(SIGDN sigdnName, out string ppszName); + void GetDisplayName(SIGDN sigdnName, out IntPtr ppszName); void GetAttributes(uint sfgaoMask, out uint psfgaoAttribs); @@ -173,12 +173,9 @@ public sealed partial class Native return (IShellItem)obj; } - public static void Free(IntPtr? managed) + public static void Free(IntPtr managed) { - if (managed != null) - { - Marshal.ReleaseComObject(managed); - } + Marshal.FreeCoTaskMem(managed); } } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Utils/ShellLocalization.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Utils/ShellLocalization.cs index a57fe1e092..830b00065d 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Utils/ShellLocalization.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Utils/ShellLocalization.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.IO; +using System.Runtime.InteropServices; using static Microsoft.CmdPal.Ext.Apps.Utils.Native; namespace Microsoft.CmdPal.Ext.Apps.Utils; @@ -45,7 +46,16 @@ public class ShellLocalization return string.Empty; } - shellItem.GetDisplayName(SIGDN.NORMALDISPLAY, out var filename); + shellItem.GetDisplayName(SIGDN.NORMALDISPLAY, out var filenamePtr); + + // get filename from ptr + var filename = Marshal.PtrToStringUni(filenamePtr); + Marshal.FreeCoTaskMem(filenamePtr); + + if (filename == null) + { + return string.Empty; + } _ = _localizationCache.TryAdd(lowerInvariantPath, filename);