Skip to content

Commit a44e480

Browse files
committed
Resolve the marshaling
1 parent b4e1a09 commit a44e480

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,4 @@ GdipCreateBitmapFromScan0
223223
BITMAP
224224
GetObject
225225
_SICHINTF
226+
RoGetAgileReference

src/Files.App/ViewModels/UserControls/Widgets/QuickAccessWidgetViewModel.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
using Windows.Storage;
88
using Windows.System;
99
using Windows.UI.Core;
10+
using Windows.Win32;
1011
using Windows.Win32.Foundation;
12+
using Windows.Win32.System.Com;
13+
using Windows.Win32.System.WinRT;
1114
using Windows.Win32.UI.Shell;
1215

1316
namespace Files.App.ViewModels.UserControls.Widgets
@@ -183,8 +186,31 @@ public override async Task ExecutePinToSidebarCommand(WidgetCardItem? item)
183186
if (item is not WidgetFolderCardItem folderCardItem || folderCardItem.Path is null)
184187
return;
185188

189+
HRESULT hr = default;
190+
using ComPtr<IAgileReference> pAgileReference = default;
191+
192+
unsafe
193+
{
194+
hr = PInvoke.RoGetAgileReference(
195+
AgileReferenceOptions.AGILEREFERENCE_DEFAULT,
196+
IID.IID_IShellItem,
197+
(IUnknown*)folderCardItem.Item.ThisPtr.Get(),
198+
pAgileReference.GetAddressOf());
199+
}
200+
186201
// Pin to Quick Access on Windows
187-
HRESULT hr = await STATask.Run(() => folderCardItem.Item.TryInvokeContextMenuVerb("pintohome"));
202+
hr = await STATask.Run(() =>
203+
{
204+
unsafe
205+
{
206+
using ComPtr<IShellItem> pShellItem = default;
207+
hr = pAgileReference.Get()->Resolve(IID.IID_IShellItem, (void**)pShellItem.GetAddressOf());
208+
var windowsFile = new WindowsFile(pShellItem);
209+
210+
return windowsFile.TryInvokeContextMenuVerb("pintohome");
211+
}
212+
});
213+
188214
if (hr.ThrowIfFailedOnDebug().Failed)
189215
return;
190216

0 commit comments

Comments
 (0)