/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/powerdisplay/PowerDisplay.Lib/Drivers/PInvoke.cs
118 строк
5 KB
moooyo
[PD] Clean up PowerDisplay: fix resource leaks, remove dead code, and fix some bugs (#46979)
13 апр 2026, 21:00
Не верифицирован
13 апр 2026, 21:00
ff87dce
Код
Авторство
О чём код?
// 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 PowerDisplay.Common.Drivers { /// <summary> /// P/Invoke declarations using LibraryImport source generator /// </summary> internal static partial class PInvoke { // ==================== User32.dll - Display Configuration ==================== [LibraryImport("user32.dll")] internal static partial int GetDisplayConfigBufferSizes( uint flags, out uint numPathArrayElements, out uint numModeInfoArrayElements); // Use unsafe pointer to avoid runtime marshalling [LibraryImport("user32.dll")] internal static unsafe partial int QueryDisplayConfig( uint flags, ref uint numPathArrayElements, DisplayConfigPathInfo* pathArray, ref uint numModeInfoArrayElements, DisplayConfigModeInfo* modeInfoArray, IntPtr currentTopologyId); [LibraryImport("user32.dll")] internal static unsafe partial int DisplayConfigGetDeviceInfo( DisplayConfigTargetDeviceName* deviceName); [LibraryImport("user32.dll")] internal static unsafe partial int DisplayConfigGetDeviceInfo( DisplayConfigSourceDeviceName* sourceName); // ==================== User32.dll - Monitor Enumeration ==================== [LibraryImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool EnumDisplayMonitors( IntPtr hdc, IntPtr lprcClip, NativeDelegates.MonitorEnumProc lpfnEnum, IntPtr dwData); [LibraryImport("user32.dll", EntryPoint = "GetMonitorInfoW", StringMarshalling = StringMarshalling.Utf16)] [return: MarshalAs(UnmanagedType.Bool)] internal static unsafe partial bool GetMonitorInfo( IntPtr hMonitor, MonitorInfoEx* lpmi); [LibraryImport("user32.dll", EntryPoint = "EnumDisplaySettingsW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] [return: MarshalAs(UnmanagedType.Bool)] internal static unsafe partial bool EnumDisplaySettings( [MarshalAs(UnmanagedType.LPWStr)] string? lpszDeviceName, int iModeNum, DevMode* lpDevMode); [LibraryImport("user32.dll", EntryPoint = "ChangeDisplaySettingsExW", StringMarshalling = StringMarshalling.Utf16)] internal static unsafe partial int ChangeDisplaySettingsEx( [MarshalAs(UnmanagedType.LPWStr)] string? lpszDeviceName, DevMode* lpDevMode, IntPtr hwnd, uint dwflags, IntPtr lParam); // ==================== Dxva2.dll - DDC/CI Monitor Control ==================== [LibraryImport("Dxva2.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool GetNumberOfPhysicalMonitorsFromHMONITOR( IntPtr hMonitor, out uint pdwNumberOfPhysicalMonitors); // Use unsafe pointer to avoid ArraySubType limitation [LibraryImport("Dxva2.dll", StringMarshalling = StringMarshalling.Utf16)] [return: MarshalAs(UnmanagedType.Bool)] internal static unsafe partial bool GetPhysicalMonitorsFromHMONITOR( IntPtr hMonitor, uint dwPhysicalMonitorArraySize, PhysicalMonitor* pPhysicalMonitorArray); [LibraryImport("Dxva2.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool DestroyPhysicalMonitor(IntPtr hMonitor); [LibraryImport("Dxva2.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool GetVCPFeatureAndVCPFeatureReply( IntPtr hPhysicalMonitor, byte bVCPCode, IntPtr pvct, out uint pdwCurrentValue, out uint pdwMaximumValue); [LibraryImport("Dxva2.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool SetVCPFeature( IntPtr hPhysicalMonitor, byte bVCPCode, uint dwNewValue); [LibraryImport("Dxva2.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool GetCapabilitiesStringLength( IntPtr hPhysicalMonitor, out uint pdwCapabilitiesStringLengthInCharacters); [LibraryImport("Dxva2.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool CapabilitiesRequestAndCapabilitiesReply( IntPtr hPhysicalMonitor, IntPtr pszASCIICapabilitiesString, uint dwCapabilitiesStringLengthInCharacters); } }