Skip to content

Commit 7796d53

Browse files
committed
Use HANDLE instead of SafeFileHandle
1 parent 092caa3 commit 7796d53

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/Files.App/App.xaml.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Microsoft.Extensions.Logging;
66
using Microsoft.UI.Xaml;
77
using Microsoft.UI.Xaml.Controls;
8-
using Microsoft.Win32.SafeHandles;
8+
using Windows.Win32.Foundation;
99
using Windows.Win32;
1010
using Microsoft.Windows.AppLifecycle;
1111
using Windows.ApplicationModel;
@@ -225,9 +225,9 @@ private async void Window_Closed(object sender, WindowEventArgs args)
225225
var results = items.Select(x => x.ItemPath).ToList();
226226
System.IO.File.WriteAllLines(OutputPath, results);
227227

228-
SafeFileHandle eventHandle = PInvoke.CreateEvent(null, false, false, "FILEDIALOG");
228+
HANDLE eventHandle = (HANDLE)PInvoke.CreateEvent(null, false, false, "FILEDIALOG").DangerousGetHandle();
229229
PInvoke.SetEvent(eventHandle);
230-
eventHandle.Close();
230+
PInvoke.CloseHandle(eventHandle);
231231
}
232232

233233
// Continue running the app on the background

src/Files.App/Program.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Windows.ApplicationModel.Activation;
1313
using Windows.Storage;
1414
using static Files.App.Helpers.Win32PInvoke;
15-
using Microsoft.Win32.SafeHandles;
1615

1716
namespace Files.App
1817
{
@@ -253,7 +252,7 @@ private static async void OnActivated(object? sender, AppActivationArguments arg
253252
/// </remarks>
254253
public static void RedirectActivationTo(AppInstance keyInstance, AppActivationArguments args)
255254
{
256-
SafeFileHandle eventHandle = PInvoke.CreateEvent(null, true, false, null);
255+
HANDLE eventHandle = (HANDLE)PInvoke.CreateEvent(null, true, false, null).DangerousGetHandle();
257256

258257
Task.Run(() =>
259258
{
@@ -265,7 +264,7 @@ public static void RedirectActivationTo(AppInstance keyInstance, AppActivationAr
265264
CWMO_DEFAULT,
266265
INFINITE,
267266
1,
268-
[eventHandle.DangerousGetHandle()],
267+
[eventHandle],
269268
out uint handleIndex);
270269
}
271270

@@ -276,7 +275,7 @@ public static void OpenShellCommandInExplorer(string shellCommand, int pid)
276275

277276
public static void OpenFileFromTile(string filePath)
278277
{
279-
SafeFileHandle eventHandle = PInvoke.CreateEvent(null, true, false, null);
278+
HANDLE eventHandle = (HANDLE)PInvoke.CreateEvent(null, true, false, null).DangerousGetHandle();
280279

281280
Task.Run(() =>
282281
{
@@ -288,7 +287,7 @@ public static void OpenFileFromTile(string filePath)
288287
CWMO_DEFAULT,
289288
INFINITE,
290289
1,
291-
[eventHandle.DangerousGetHandle()],
290+
[eventHandle],
292291
out uint handleIndex);
293292
}
294293
}

0 commit comments

Comments
 (0)