mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
[PT Run] Refactoring: combined all NativeMethods.cs files for plugins… (#15807)
* [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
This commit is contained in:
1094
src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs
Normal file
1094
src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs
Normal file
File diff suppressed because it is too large
Load Diff
48
src/modules/launcher/Wox.Plugin/Common/Win32/Win32Helpers.cs
Normal file
48
src/modules/launcher/Wox.Plugin/Common/Win32/Win32Helpers.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
// 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;
|
||||
using System.Text;
|
||||
using SuppressMessageAttribute = System.Diagnostics.CodeAnalysis.SuppressMessageAttribute;
|
||||
|
||||
namespace Wox.Plugin.Common.Win32
|
||||
{
|
||||
[SuppressMessage("Interoperability", "CA1401:P/Invokes should not be visible", Justification = "We want plugins to share this NativeMethods class, instead of each one creating its own.")]
|
||||
public static class NativeMethods
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool EnumThreadWindows(uint threadId, ShellCommand.EnumThreadDelegate lpfn, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int nMaxCount);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetWindowTextLength(IntPtr hwnd);
|
||||
|
||||
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
|
||||
public static extern HRESULT SHLoadIndirectString(string pszSource, StringBuilder pszOutBuf, uint cchOutBuf, IntPtr ppvReserved);
|
||||
}
|
||||
|
||||
[SuppressMessage("Design", "CA1028:Enum Storage should be Int32", Justification = "These values are used by win32 api")]
|
||||
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "These are the names win32 api uses.")]
|
||||
public enum HRESULT : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Operation successful.
|
||||
/// </summary>
|
||||
S_OK = 0x00000000,
|
||||
|
||||
/// <summary>
|
||||
/// Operation successful. (negative condition/no operation)
|
||||
/// </summary>
|
||||
S_FALSE = 0x00000001,
|
||||
|
||||
/// <summary>
|
||||
/// Not implemented.
|
||||
/// </summary>
|
||||
E_NOTIMPL = 0x80004001,
|
||||
|
||||
/// <summary>
|
||||
/// No such interface supported.
|
||||
/// </summary>
|
||||
E_NOINTERFACE = 0x80004002,
|
||||
|
||||
/// <summary>
|
||||
/// Pointer that is not valid.
|
||||
/// </summary>
|
||||
E_POINTER = 0x80004003,
|
||||
|
||||
/// <summary>
|
||||
/// Operation aborted.
|
||||
/// </summary>
|
||||
E_ABORT = 0x80004004,
|
||||
|
||||
/// <summary>
|
||||
/// Unspecified failure.
|
||||
/// </summary>
|
||||
E_FAIL = 0x80004005,
|
||||
|
||||
/// <summary>
|
||||
/// Unexpected failure.
|
||||
/// </summary>
|
||||
E_UNEXPECTED = 0x8000FFFF,
|
||||
|
||||
/// <summary>
|
||||
/// General access denied error.
|
||||
/// </summary>
|
||||
E_ACCESSDENIED = 0x80070005,
|
||||
|
||||
/// <summary>
|
||||
/// Handle that is not valid.
|
||||
/// </summary>
|
||||
E_HANDLE = 0x80070006,
|
||||
|
||||
/// <summary>
|
||||
/// Failed to allocate necessary memory.
|
||||
/// </summary>
|
||||
E_OUTOFMEMORY = 0x8007000E,
|
||||
|
||||
/// <summary>
|
||||
/// One or more arguments are not valid.
|
||||
/// </summary>
|
||||
E_INVALIDARG = 0x80070057,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user