/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/MouseUtils/MouseJump.Common/Interop/ResultHandler_uint.cs
54 строки
2 KB
Michael Clayton
Ready for Review - [Mouse Jump] - port upstream WinUI3 code to Mouse Jump (microsoft#48290) (#48393)
07 авг 2026, 08:34
Не верифицирован
07 авг 2026, 08:34
e0010c5
Код
Авторство
О чём код?
// 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.ComponentModel; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace MouseJump.Common.Interop; public static partial class ResultHandler { /* helpers for handling results from Win32 API calls that return a uint value, throwing exceptions when errors occur, and reading the last error code when necessary. */ public static void HandleFailure( uint result, bool getLastError = false, [CallerMemberName] string memberName = "") { var lastError = getLastError ? (int?)Marshal.GetLastPInvokeError() : null; ResultHandler.HandleFailure(result, lastError, memberName); } public static void HandleFailure( uint result, Func<int>? getLastError, [CallerMemberName] string memberName = "") { var lastError = getLastError?.Invoke(); ResultHandler.HandleFailure(result, lastError, memberName); } public static void HandleFailure( uint result, int? lastError, [CallerMemberName] string memberName = "") { var lines = new List<string> { $"{memberName} failed with result {result}.", }; if (lastError is not null) { lines.Add($"last error was '{lastError}'"); } var message = string.Join(Environment.NewLine, lines); throw new Win32Exception(message); } }