From 5a97db8992def6da2795ef7634f7edb393000a69 Mon Sep 17 00:00:00 2001 From: Andrey Nekrasov Date: Wed, 28 Jul 2021 17:26:06 +0300 Subject: [PATCH] [CDPX] Fix build: move dll imports to NativeMethods (#12544) --- .../Helpers/NativeMethods.cs | 7 +++++++ .../ViewModels/ShellViewModel.cs | 10 ++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Helpers/NativeMethods.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Helpers/NativeMethods.cs index 176c10a735..04df5f3a12 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Helpers/NativeMethods.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Helpers/NativeMethods.cs @@ -2,6 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Runtime.InteropServices; namespace Microsoft.PowerToys.Settings.UI.Helpers @@ -20,6 +21,12 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers [DllImport("user32.dll")] public static extern bool AllowSetForegroundWindow(int dwProcessId); + + [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] + public static extern IntPtr LoadLibrary(string dllToLoad); + + [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] + public static extern bool FreeLibrary(IntPtr hModule); #pragma warning restore CA1401 // P/Invokes should not be visible } } diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/ViewModels/ShellViewModel.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/ViewModels/ShellViewModel.cs index 61e675d1f1..4e30e62858 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/ViewModels/ShellViewModel.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/ViewModels/ShellViewModel.cs @@ -38,21 +38,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels set { Set(ref isBackEnabled, value); } } - [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] - private static extern IntPtr LoadLibrary(string dllToLoad); - - [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] - private static extern bool FreeLibrary(IntPtr hModule); - public bool IsVideoConferenceBuild { get { - var mfHandle = LoadLibrary("mf.dll"); + var mfHandle = NativeMethods.LoadLibrary("mf.dll"); bool mfAvailable = mfHandle != null; if (mfAvailable) { - FreeLibrary(mfHandle); + NativeMethods.FreeLibrary(mfHandle); } return this != null && File.Exists("modules/VideoConference/VideoConferenceModule.dll") && mfAvailable;