mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
* [PT Run] Refactoring: combined all NativeMethods.cs files for plugins into Wox.Plugin/Common/Win32/ * Fixed spell check * [PT Run] Changed NativeMethods.Helpers to Win32Helpers (seperate class) to not conflict with Microsoft.PowerToys.Settings.UI.Library.Helpers * [PT Run] Renamed Constants.cs to ConstantsAndStructs.cs and moved all of them from NativeMethods.cs * [PT Run] Merged ConstantsAndStructs.cs into NativeMethods.cs and renamed Constants to Win32Constants to avoid conflicting * [PT Run] Added missing summaries + fixed missed refactored method * [PT Run] Use using directive instead of alias + updated method call for .Net 6 * [PT Run] Fixed missed using alias + spell check
49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// 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 Wox.Plugin.Common.Win32
|
|
{
|
|
public static class Win32Helpers
|
|
{
|
|
/// <summary>
|
|
/// Detects the type of system firmware which is equal to the boot type by calling the method <see cref="NativeMethods.GetFirmwareType"/>.
|
|
/// </summary>
|
|
/// <returns>Firmware type like Uefi or Bios.</returns>
|
|
public static FirmwareType GetSystemFirmwareType()
|
|
{
|
|
FirmwareType firmwareType = default;
|
|
_ = NativeMethods.GetFirmwareType(ref firmwareType);
|
|
return firmwareType;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the last Win32 Error code thrown by a native method if enabled for this method.
|
|
/// </summary>
|
|
/// <returns>The error code as int value.</returns>
|
|
public static int GetLastError()
|
|
{
|
|
return Marshal.GetLastPInvokeError();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validate that the handle is not null and close it.
|
|
/// </summary>
|
|
/// <param name="handle">Handle to close.</param>
|
|
/// <returns>Zero if native method fails and nonzero if the native method succeeds.</returns>
|
|
public static bool CloseHandleIfNotNull(IntPtr handle)
|
|
{
|
|
if (handle == IntPtr.Zero)
|
|
{
|
|
// Return true if there is nothing to close.
|
|
return true;
|
|
}
|
|
|
|
return NativeMethods.CloseHandle(handle);
|
|
}
|
|
}
|
|
}
|