From b31a2dcc8125eb6d19f2a938f202959fe937c34a Mon Sep 17 00:00:00 2001 From: Craig Treasure Date: Thu, 10 Mar 2022 21:06:00 -0800 Subject: [PATCH] Updated CsWin32 and other dependencies (#110) * Update System.IO.Abstractions to 16.1.20 * Update CsWin32 to 0.1.635-beta * Use newly cocreatable `ShellLink` from updated CsWin32 - In CsWin32 0.1.635-beta, the `ShellLink` class became cocreatable, which allows me to restore my original method of creating a `ShellLink`. See https://github.com/microsoft/CsWin32/issues/453. --- Packages.props | 4 ++-- src/StartMenuCleaner/NativeMethods.txt | 2 +- src/StartMenuCleaner/Utils/CsWin32ShortcutHandler.cs | 9 +++------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Packages.props b/Packages.props index 71fb7c1..85a8d47 100644 --- a/Packages.props +++ b/Packages.props @@ -2,7 +2,7 @@ 6.0.0 - 16.1.16 + 16.1.20 @@ -18,7 +18,7 @@ - + diff --git a/src/StartMenuCleaner/NativeMethods.txt b/src/StartMenuCleaner/NativeMethods.txt index ea3152c..36eedf4 100644 --- a/src/StartMenuCleaner/NativeMethods.txt +++ b/src/StartMenuCleaner/NativeMethods.txt @@ -2,4 +2,4 @@ IPersistFile IShellLinkW MAX_PATH ShellLink -STGM_READ +STGM diff --git a/src/StartMenuCleaner/Utils/CsWin32ShortcutHandler.cs b/src/StartMenuCleaner/Utils/CsWin32ShortcutHandler.cs index 485a543..dda2eec 100644 --- a/src/StartMenuCleaner/Utils/CsWin32ShortcutHandler.cs +++ b/src/StartMenuCleaner/Utils/CsWin32ShortcutHandler.cs @@ -4,6 +4,7 @@ namespace StartMenuCleaner.Utils; using Windows.Win32; using Windows.Win32.Storage.FileSystem; using Windows.Win32.System.Com; +using Windows.Win32.System.Com.StructuredStorage; using Windows.Win32.UI.Shell; internal class CsWin32ShortcutHandler : IFileShortcutHandler @@ -15,15 +16,11 @@ public unsafe string ResolveTarget(string shortcutPath) throw new NotSupportedException($"{nameof(ResolveTarget)} is only supported on Windows 5.1.2600+."); } - // See the following issues for current status and new advice: - // https://github.com/microsoft/CsWin32/issues/453 - // https://github.com/microsoft/CsWin32/discussions/323 - IPersistFile shellLink = (IPersistFile)(Activator.CreateInstance(Type.GetTypeFromCLSID(typeof(ShellLink).GUID, throwOnError: true)!) - ?? throw new InvalidOperationException("Failed to create an instance of ShellLink")); + IPersistFile shellLink = (IPersistFile)new ShellLink(); fixed (char* shortcutFilePathPcwstr = shortcutPath) { - shellLink.Load(shortcutFilePathPcwstr, PInvoke.STGM_READ); + shellLink.Load(shortcutFilePathPcwstr, (uint)STGM.STGM_READ); } Span szShortcutTargetPath = stackalloc char[(int)PInvoke.MAX_PATH];