Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

c++ - SetSuspendState() API never returns in Win8

Let me explain my problem statement:

In my VC++ project I want to insert a logic to send my system (Windows 8) to Sleep state programatically & resume back.

I'm doing it like this (Copying the code snippet) ::

int wait = 100;
LARGE_INTEGER WaitTime;
    WaitTime.QuadPart = wait;
    WaitTime.QuadPart *= -10000000;

HANDLE hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
        if(0 == SetWaitableTimer(hTimer, &WaitTime, 0, NULL, NULL, TRUE))
        {
            res = false;
            return res;
        }
        if(0 == SetSuspendState(FALSE, FALSE, FALSE))
        {
            res = false;
            return res;
        }

The system is going to sleep (monitor is getting turned off).
Here, I want to resume back from sleep state after SetSuspendState() API call. But I see the SetSuspendState() call is not at all returning. The control would be struck at the this SetSuspendState() call itself & doesn't return back.

However, if I forcefully bring the system back to power , I see it come back but the function "SetSuspendState()" doesn't return back in my code.

Can anyone please help me to figure out why is the SetSuspendState() not returning back & how to fix this problem. Thanks in advance.

PS: I'm using VS remote debugger mechanism to achieve this sleep state.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I imagine that the call to SetSuspendState results in the remote debug server being shutdown. When you call SetSuspendState the system starts a shutdown, and that involves notifying all applications that the system is going down. When that happens, those applications are expected to terminate. So you can expect to lose your connection to the remote debugger.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...