mirror of https://github.com/dahall/Vanara.git
Added nullability to PowrProf
parent
1df1439cfb
commit
5572f7429a
|
@ -1,7 +1,3 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Vanara.InteropServices;
|
||||
|
||||
namespace Vanara.PInvoke;
|
||||
|
||||
/// <summary>Functions, structures and constants from powrprof.dll.</summary>
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Vanara.InteropServices;
|
||||
|
||||
namespace Vanara.PInvoke;
|
||||
|
||||
public static partial class PowrProf
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Vanara.InteropServices;
|
||||
|
||||
namespace Vanara.PInvoke;
|
||||
|
||||
|
@ -3656,21 +3652,20 @@ public static partial class PowrProf
|
|||
return f(g1.HasValue ? (IntPtr)(void*)&ptrs[0] : IntPtr.Zero, g2.HasValue ? (IntPtr)(void*)&ptrs[1] : IntPtr.Zero, g3.HasValue ? (IntPtr)(void*)&ptrs[2] : IntPtr.Zero);
|
||||
}
|
||||
|
||||
private static SafeHGlobalHandle PwrReadMem(PwrReadMemFunc f, Guid? g1, Guid? g2, Guid? g3)
|
||||
{
|
||||
return PwrGuidTsl(g1, g2, g3, (p1, p2, p3) => {
|
||||
private static SafeHGlobalHandle PwrReadMem(PwrReadMemFunc f, Guid? g1, Guid? g2, Guid? g3) =>
|
||||
PwrGuidTsl(g1, g2, g3, (p1, p2, p3) =>
|
||||
{
|
||||
var sz = 0U;
|
||||
var err = f(HKEY.NULL, p1, p2, p3, IntPtr.Zero, ref sz);
|
||||
if (err.Failed)
|
||||
{
|
||||
if (err == Win32Error.ERROR_FILE_NOT_FOUND) return null;
|
||||
if (err != Win32Error.ERROR_MORE_DATA) throw err.GetException();
|
||||
if (err == Win32Error.ERROR_FILE_NOT_FOUND) return SafeHGlobalHandle.Null;
|
||||
if (err != Win32Error.ERROR_MORE_DATA) throw err.GetException()!;
|
||||
}
|
||||
var p = new SafeHGlobalHandle((int)sz);
|
||||
f(HKEY.NULL, p1, p2, p3, (IntPtr)p, ref sz).ThrowIfFailed();
|
||||
return p;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>Contains parameters used when registering for a power notification.</summary>
|
||||
// https://docs.microsoft.com/en-us/windows/desktop/api/powrprof/ns-powrprof-device_notify_subscribe_parameters typedef struct
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,12 +1,6 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Vanara.Extensions;
|
||||
using static Vanara.PInvoke.PowrProf;
|
||||
|
||||
namespace Vanara.PInvoke.Tests;
|
||||
|
@ -19,7 +13,7 @@ public class PowrProfTests
|
|||
{
|
||||
Assert.That(EnumPwrSchemes(p), Is.True);
|
||||
|
||||
bool p(uint uiIndex, uint dwName, string sName, uint dwDesc, string sDesc, in POWER_POLICY pp, IntPtr lParam)
|
||||
static bool p(uint uiIndex, uint dwName, string sName, uint dwDesc, string sDesc, in POWER_POLICY pp, IntPtr lParam)
|
||||
{
|
||||
TestContext.WriteLine($"Idx:{uiIndex}; Name:{sName}; Desc:{sDesc}");
|
||||
return true;
|
||||
|
@ -45,13 +39,13 @@ public class PowrProfTests
|
|||
}
|
||||
}
|
||||
|
||||
void WriteName(Guid? sch, Guid? grp, Guid? setting) { TestContext.WriteLine($"{PowerReadFriendlyName(sch, grp, setting)} : {PowerReadDescription(sch, grp, setting)} : {setting}"); }
|
||||
static void WriteName(Guid? sch, Guid? grp, Guid? setting) => TestContext.WriteLine($"{PowerReadFriendlyName(sch, grp, setting)} : {PowerReadDescription(sch, grp, setting)} : {setting}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PowerReadSettingAttributesTest()
|
||||
{
|
||||
var attr = PowerReadSettingAttributes(default(Guid), default(Guid));
|
||||
var attr = PowerReadSettingAttributes(default, default);
|
||||
TestContext.WriteLine($"DefGuid={attr}");
|
||||
attr = PowerReadSettingAttributes(GUID_SYSTEM_BUTTON_SUBGROUP, default);
|
||||
TestContext.WriteLine($"GUID_SYSTEM_BUTTON_SUBGROUP={attr}");
|
||||
|
@ -61,7 +55,7 @@ public class PowrProfTests
|
|||
public void PowerSettingRegisterNotificationTest()
|
||||
{
|
||||
uint timeOut = 0;
|
||||
var evt = new AutoResetEvent(false);
|
||||
AutoResetEvent evt = new(false);
|
||||
Assert.That(PowerSettingRegisterNotification(GUID_VIDEO_POWERDOWN_TIMEOUT, DEVICE_NOTIFY.DEVICE_NOTIFY_CALLBACK, new DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS { Callback = PowerSettingFunc }, out var powerNotification), ResultIs.Successful);
|
||||
evt.WaitOne(1000);
|
||||
Assert.That(PowerSettingUnregisterNotification(powerNotification), ResultIs.Successful);
|
||||
|
|
Loading…
Reference in New Issue