Page 1 of 1

ReadPwrScheme ... WritePwrScheme

Posted: Wed Mar 30, 2005 8:51 am
by bingo
read powerscheme "4" and write it as "9" with new name/description .

Code: Select all

Structure POWER_ACTION_POLICY
Action.l
Flags.l
EventCode.l
EndStructure 

Structure MACHINE_POWER_POLICY
Revision.l
MinSleepAc.l
MinSleepDc.l
ReducedLatencySleepAc.l
ReducedLatencySleepDc.l
DozeTimeoutAc.l
DozeTimeoutDc.l
DozeS4TimeoutAc.l
DozeS4TimeoutDc.l
MinThrottleAc.b
MinThrottleDc.b
pad1.b[2]
OverThrottledAc.POWER_ACTION_POLICY
OverThrottledDc.POWER_ACTION_POLICY
EndStructure 

Structure USER_POWER_POLICY
Revision.l
IdleAc.POWER_ACTION_POLICY
IdleDc.POWER_ACTION_POLICY
IdleTimeoutAc.l
IdleTimeoutDc.l
IdleSensitivityAc.b
IdleSensitivityDc.b
ThrottlePolicyAc.b
ThrottlePolicyDc.b
MaxSleepAc.l
MaxSleepDc.l
Reserved.l[2]
VideoTimeoutAc.l
VideoTimeoutDc.l
SpindownTimeoutAc.l
SpindownTimeoutDc.l
OptimizeForPowerAc.b
OptimizeForPowerDc.b
FanThrottleToleranceAc.b
FanThrottleToleranceDc.b
ForcedThrottleAc.b
ForcedThrottleDc.b
EndStructure 

Structure POWER_POLICY
user.USER_POWER_POLICY
mach.MACHINE_POWER_POLICY
EndStructure 


PP.POWER_POLICY


OpenLibrary(1, "PowrProf.DLL")
F1 = IsFunction(1, "ReadPwrScheme")
F2 = IsFunction(1, "WritePwrScheme")

CallFunctionFast(F1,4,@PP)

scheme.s = "scheme 9"

schemeinfo.s = "scheme 9 info"

Debug CallFunctionFast(F2,9,@scheme,@schemeinfo,@PP) ;<- crash !
CloseLibrary(1) 
http://msdn.microsoft.com/library/defau ... scheme.asp

the code crashs on WritePwrScheme :cry: - any hints ?

Posted: Wed Mar 30, 2005 2:15 pm
by MrMat
The 9 in CallFunctionFast(F2,9,@scheme,@schemeinfo,@PP) should be a pointer to a long so you could have:

Code: Select all

schemenum.l = 9
CallFunctionFast(F2,@schemenum,@scheme,@schemeinfo,@PP)
Also the strings scheme and schemeinfo should be converted to unicode first. It seems to work ok if you use the code from http://www.purearea.net/pb/CodeArchiv/S ... Unicode.pb to convert them. Hope you get it working!

Posted: Wed Mar 30, 2005 2:36 pm
by bingo
ok ... maybe a bug in this msdn-doc
http://msdn.microsoft.com/library/defau ... scheme.asp


lpszName
[in] Pointer to a null-terminated string that specifies the name of the power scheme.
lpszDescription
[in] Pointer to a null-terminated string that specifies the description of the power scheme.


but works with unicode ONLY ! thanks :wink:

Posted: Wed Mar 30, 2005 2:40 pm
by MrMat
Those are the names of the variables. Their types in the box above show the strings are unicode so i don't think it's a bug:

Code: Select all

BOOLEAN WritePwrScheme(
  PUINT puiID,
  LPWSTR lpszName,
  LPWSTR lpszDescription,
  PPOWER_POLICY pPowerPolicy
);
Hope you got it working! :)