문제

I'm coding using C++ with WinAPIs, and to hibernate the computer I use the following call:

SetSuspendState(TRUE, NULL, FALSE);

But what happens is that if the computer has larger RAM array installed the hibernation fails.

So I was wondering, does Windows send any notifications if hibernation fails? And if not, how to tell if my request to hibernate failed?

도움이 되었습니까?

해결책

Looks like there's no direct way to detect hibernation [CORRECTION: I was wrong about this. See Fowl's answer.] until Windows 8 (see PowerRegisterSuspendResumeNotification). But I suppose you could idle-loop and watch the system time. If the time suddenly jumps forwards, you've successfully hibernated (and resumed!) and if this hasn't happened within a minute or so the request probably failed. I think you can use the GetTickCount64 function, which is insensitive to system time changes but apparently includes a bias for time spent sleeping. If this doesn't work, use GetSystemTimeAsFileTime but also watch for WM_TIMECHANGE messages.

You could also check on the system in question whether Windows writes anything to the event log when hibernation fails. If so, your application could monitor the event log for the relevant entry. This would be a more reliable approach.

다른 팁

Register for (RegisterPowerSettingNotification), then listen for WM_POWERBROADCAST, and then interrogate the event log to get more detail.

There's a bit of messing around if you want to handle multiple OS versions, but it's doable.

Hm... maybe I'm missing the point here, but according to the docs it should return FALSE if it failed. Does it still return TRUE in your case?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top