-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] PowrProf.PowerSettingRegisterNotification #122
Comments
I've looked into your question and apologize. There is both a bug and a few omissions that are making this hard for you. I've corrected them and committed the updates. They will get released in the next version, due shortly. Here is the function to get the value you want. public uint GetVideoPowerdownTimeout()
{
uint timeOut = 0;
var evt = new AutoResetEvent(false);
PowerSettingRegisterNotification(GUID_VIDEO_POWERDOWN_TIMEOUT, DEVICE_NOTIFY.DEVICE_NOTIFY_CALLBACK, new DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS { Callback = PowerSettingFunc }, out var powerNotification).ThrowIfFailed();
evt.WaitOne(1000);
PowerSettingUnregisterNotification(powerNotification).ThrowIfFailed();
return timeOut;
Win32Error PowerSettingFunc(IntPtr Context, uint Type, IntPtr Setting)
{
if (Type == (uint)User32.PowerBroadcastType.PBT_POWERSETTINGCHANGE && Setting != IntPtr.Zero)
{
var pbSetting = Setting.ToStructure<User32.POWERBROADCAST_SETTING>();
if (pbSetting.DataLength == Marshal.SizeOf(typeof(uint)))
timeOut = BitConverter.ToUInt32(pbSetting.Data, 0);
}
evt.Set();
return Win32Error.ERROR_SUCCESS;
}
} |
@dahall |
You can pull the 3.2.8 build now as prerelease from AppVeyor's project NuGet source at https://ci.appveyor.com/nuget/vanara-prerelease. |
First of all, excellent library/wrappers. Thank you for this!
I have been stuck trying to figure out why I cannot get
PowrProf.PowerSettingRegisterNotification
to work. I am trying to read/set a power setting in Win32.Specifically: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa
SPI_GETPOWEROFFTIMEOUT
&SPI_SETPOWEROFFTIMEOUT
Both of these are not supported and references
GUID_VIDEO_POWERDOWN_TIMEOUT
that says to useRegisterPowerSettingsNotification
: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerpowersettingnotificationI found these under your
PowrProf
wrapper and have been attempting to get it work. So far, I receive a good message back fromPowrProf.PowerSettingRegisterNotification
:I may not be creating the
IntPtr
for the recipient correctly? I may not be fully understanding how to utilize the wrapper without reinventing the wheel. I haven't worked much with Win32/PInvoke, but not getting far from trial/error and example research. The simple console application example I have abruptly closes after a couple of seconds. Virtually not making it to the while loop to give me time to change the setting in Windows and print the changed value:The text was updated successfully, but these errors were encountered: