Board index » cppbuilder » SetSystemPowerState issues

SetSystemPowerState issues


2006-05-19 11:46:17 PM
cppbuilder48
Hi guys - it must be bug Friday for me today, two posts in a row.
Having another issue, this time relating to SetSystemPowerState(). In our
application be have a system, similar to the Microsoft shutdown dialog where
the user can choose how they want to close the Windows session i.e. restart,
shutdown, hibernate or stand-by.
All options seem to work except the hibernate / stand-by. The only way i
could find to implement either of these was with SetSystemPowerState().
However I have discovered that on some systems you do not seem to be able to
place the OS in either of these states i.e. if you use the normal MS
shutdown dialog it does not have either of these options available. And in
following with this, if our application tried to implement a stand-by or
hibernate on these systems, it causes considerable problems resulting in
BSOD and system restart.
What usually happens is that the system will a) display the MS shutdown
message but not proceed any further, or b) appear to hibernate but not turn
off the PSU / CPU fans. When (b) happens, if I try to re-activate the
system using the power button, it appear to re-start and then I get a
page-fault BSOD.
What I need to know is, is there any way to detect or determine if the
system can or can't be placed in either of theses modes? I've notices on
the Windows XP Home edition shutdown that under certain circumstances and
configurations, the Stand-By or Hibernate buttons may be disabled. This is
exactly what I need to determine...
My second question, (in following with this) is, does my application (or any
other running on the system) need to perform any specialist operations
before the system is suspended. For example, we have a hardware polling
thread - does this need to be specifically suspended by our application or
does the OS take care of these aspects?
As usual, any help or pointers would be gratefully received,
Many thanks in advance,
Mike C
 
 

Re:SetSystemPowerState issues

Mike Collins wrote:
Quote
All options seem to work except the hibernate / stand-by. The only way i
could find to implement either of these was with SetSystemPowerState().

What I need to know is, is there any way to detect or determine if the
system can or can't be placed in either of theses modes?
I think you want to look at GetPwrCapabilities()
msdn.microsoft.com/library/default.asp
I should think that HiberFilePresent would indicate if hibernation is
available.
Don't know what the various SystemS1 sleep states are.
Quote
My second question, (in following with this) is, does my application (or any
other running on the system) need to perform any specialist operations
before the system is suspended. For example, we have a hardware polling
thread - does this need to be specifically suspended by our application or
does the OS take care of these aspects?
Well, that depends on if your hardware/polling can withstand a long
interruption. If your application or the hardware crashes with sleep
or hibernate, then, yes, they should check for those system messages
and take care of themselves. If they don't care about the missed
polls, then nothing is needed. The app will just go to sleep.
 

Re:SetSystemPowerState issues

Thanks bob, got me looking in the right place in MSDN now. Whilst there I
also noticed, IsPwrSuspendAllowed() and IsPwrHibernateAllowed(). I'm just
testing them now but the names allow sound promising...
Thanks alot
"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
Quote
Mike Collins wrote:

 

{smallsort}

Re:SetSystemPowerState issues

By the way, is there aomething specific you need to do to use the functions
in powrprof.h?
Do you have to dynamically load the DLL and use GetProcAddress?
Thanks again, mike...
"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
Quote
Mike Collins wrote:

 

Re:SetSystemPowerState issues

Mike Collins wrote:
Quote
By the way, is there aomething specific you need to do to use the functions
in powrprof.h?
You would want to link with the lib file.
But it sounds like if you did, then your application wouldn't run on a
95 system. With LoadLibrary, you could detect that, and disable the
specials.
To get a lib file to link with, locate the dll, and use implib on it.
Quote
Do you have to dynamically load the DLL and use GetProcAddress?
Might be best, if you need to also support Win95.
 

Re:SetSystemPowerState issues

"Bob Gonder" < XXXX@XXXXX.COM >wrote in message
Quote
...
Don't know what the various SystemS1 sleep states are.
...
s0 - everything is up & running
s1 - cpu halt, mem refreshing
s2 - cpu halt, mem refr. slow
s3 - cpu off, mem refr. slow (power supply low)
s4 - cpu off, mem swapped
s5 - everything is off, need reboot
 

Re:SetSystemPowerState issues

no sure:
Quote
s2 - cpu halt, mem refr. slow
should be:
s2 - cpu off, ram refr. normal
correct me please.