Fix CA 1060 by moving PInvokes to a common NativeMethodsClass

Severity Code Description Project File Line Suppression State
Warning CA1060 Move pinvokes to native methods class PowerLauncher C:\Repos\PowerToys\src\modules\launcher\PowerLauncher\App.xaml.cs 24 Active
This commit is contained in:
ryanbodrug-microsoft
2020-06-18 12:56:12 -07:00
parent b89d6d78ef
commit 165ffed9e6
11 changed files with 106 additions and 69 deletions

View File

@@ -72,6 +72,7 @@
<ItemGroup>
<ProjectReference Include="..\..\common\interop\interop.vcxproj" />
<ProjectReference Include="..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\Telemetry.csproj" />
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" />
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI\Microsoft.PowerToys.Settings.UI.csproj" />

View File

@@ -8,6 +8,7 @@ using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using interop;
using ManagedCommon;
using Windows.UI.Popups;
namespace Microsoft.PowerToys.Settings.UI.Runner
@@ -57,7 +58,7 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
IsUserAnAdmin = false;
}
WaitForPowerToysRunner();
RunnerHelper.WaitForPowerToysRunner(PowerToysPID);
ipcmanager = new TwoWayPipeMessageIPCManaged(args[1], args[0], null);
ipcmanager.Start();
@@ -78,27 +79,5 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
{
return ipcmanager;
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);
internal static void WaitForPowerToysRunner()
{
Task.Run(() =>
{
const uint INFINITE = 0xFFFFFFFF;
const uint WAIT_OBJECT_0 = 0x00000000;
const uint SYNCHRONIZE = 0x00100000;
IntPtr powerToysProcHandle = OpenProcess(SYNCHRONIZE, false, PowerToysPID);
if (WaitForSingleObject(powerToysProcHandle, INFINITE) == WAIT_OBJECT_0)
{
Environment.Exit(0);
}
});
}
}
}