diff --git a/src/Files.App.Server/Files.App.Server.csproj b/src/Files.App.Server/Files.App.Server.csproj
index 2af4dc095e40..de057e9f5400 100644
--- a/src/Files.App.Server/Files.App.Server.csproj
+++ b/src/Files.App.Server/Files.App.Server.csproj
@@ -40,7 +40,7 @@
-
+
diff --git a/src/Files.App.Server/Helpers.cs b/src/Files.App.Server/Helpers.cs
index 0bdc20a01fa3..94f01b1a44ea 100644
--- a/src/Files.App.Server/Helpers.cs
+++ b/src/Files.App.Server/Helpers.cs
@@ -3,6 +3,8 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using Windows.Win32.Foundation;
+using Windows.Win32.System.WinRT;
using WinRT;
namespace Files.App.Server;
@@ -10,33 +12,22 @@ namespace Files.App.Server;
unsafe partial class Helpers
{
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
- public static int GetActivationFactory(void* activatableClassId, void** factory)
+ public static HRESULT GetActivationFactory(HSTRING activatableClassId, IActivationFactory** factory)
{
- const int E_INVALIDARG = unchecked((int)0x80070057);
- const int CLASS_E_CLASSNOTAVAILABLE = unchecked((int)0x80040111);
- const int S_OK = 0;
-
- if (activatableClassId is null || factory is null)
+ if (activatableClassId.IsNull || factory is null)
{
- return E_INVALIDARG;
+ return HRESULT.E_INVALIDARG;
}
try
{
- IntPtr obj = Module.GetActivationFactory(MarshalString.FromAbi((IntPtr)activatableClassId));
-
- if ((void*)obj is null)
- {
- return CLASS_E_CLASSNOTAVAILABLE;
- }
-
- *factory = (void*)obj;
- return S_OK;
+ *factory = (IActivationFactory*)Module.GetActivationFactory(MarshalString.FromAbi((IntPtr)activatableClassId));
+ return *factory is null ? HRESULT.CLASS_E_CLASSNOTAVAILABLE : HRESULT.S_OK;
}
catch (Exception e)
{
ExceptionHelpers.SetErrorInfo(e);
- return ExceptionHelpers.GetHRForException(e);
+ return (HRESULT)ExceptionHelpers.GetHRForException(e);
}
}
}
\ No newline at end of file
diff --git a/src/Files.App.Server/NativeMethods.txt b/src/Files.App.Server/NativeMethods.txt
index 8868cd313d96..661dfca64d2a 100644
--- a/src/Files.App.Server/NativeMethods.txt
+++ b/src/Files.App.Server/NativeMethods.txt
@@ -1,8 +1,10 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.
+CLASS_E_CLASSNOTAVAILABLE
+E_INVALIDARG
+RoInitialize
RoRegisterActivationFactories
RoRevokeActivationFactories
WindowsCreateString
WindowsDeleteString
-RoInitialize
diff --git a/src/Files.App.Server/Program.cs b/src/Files.App.Server/Program.cs
index 7701646bd846..c5e99b80457c 100644
--- a/src/Files.App.Server/Program.cs
+++ b/src/Files.App.Server/Program.cs
@@ -21,7 +21,7 @@ static async Task Main()
{
AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException;
- nint cookie = 0;
+ RO_REGISTRATION_COOKIE cookie = default;
_ = PInvoke.RoInitialize(RO_INIT_TYPE.RO_INIT_MULTITHREADED);
@@ -42,11 +42,18 @@ static async Task Main()
unsafe
{
- var callbacks = Enumerable.Repeat((nint)(delegate* unmanaged[Stdcall])&Helpers.GetActivationFactory, classIds.Length).ToArray();
+ delegate* unmanaged[Stdcall][] callbacks = new delegate* unmanaged[Stdcall][classIds.Length];
+ for (int i = 0; i < callbacks.Length; i++)
+ {
+ callbacks[i] = &Helpers.GetActivationFactory;
+ }
- if (PInvoke.RoRegisterActivationFactories(classIds, callbacks, out cookie) is HRESULT hr && hr.Value != 0)
+ fixed (delegate* unmanaged[Stdcall]* pCallbacks = callbacks)
{
- Marshal.ThrowExceptionForHR(hr);
+ if (PInvoke.RoRegisterActivationFactories(classIds, pCallbacks, out cookie) is HRESULT hr && hr.Value != 0)
+ {
+ Marshal.ThrowExceptionForHR(hr);
+ }
}
}
diff --git a/src/Files.App/Files.App.csproj b/src/Files.App/Files.App.csproj
index 1b84e07975db..6adeb669c864 100644
--- a/src/Files.App/Files.App.csproj
+++ b/src/Files.App/Files.App.csproj
@@ -89,7 +89,7 @@
-
+
diff --git a/src/Files.App/Services/Storage/StorageNetworkService.cs b/src/Files.App/Services/Storage/StorageNetworkService.cs
index e0249c33b7c8..d784303d7611 100644
--- a/src/Files.App/Services/Storage/StorageNetworkService.cs
+++ b/src/Files.App/Services/Storage/StorageNetworkService.cs
@@ -184,7 +184,7 @@ public bool DisconnectNetworkDrive(ILocatableFolder drive)
return
PInvoke.WNetCancelConnection2W(
drive.Path.TrimEnd('\\'),
- (uint)NET_USE_CONNECT_FLAGS.CONNECT_UPDATE_PROFILE,
+ NET_CONNECT_FLAGS.CONNECT_UPDATE_PROFILE,
true)
is WIN32_ERROR.NO_ERROR;
}