Article View: borland.public.cppbuilder.nativeapi
Article #1305Can't get the computer to programmatically wake from standby.... (original question in language cpp)
From: Wiljo
Date: Fri, 14 Sep 2007 21:02
Date: Fri, 14 Sep 2007 21:02
82 lines
3898 bytes
3898 bytes
Hi,
Original question was in <language cpp>, but it was suggested to post
this question here. So here it is again. Sorry for the inconvenience.
I am writing a PVCR program to schedule recording of TV shows, and I
want the computer to allow the Standby mode between recordings. I am
using waitable timers in order to wake up the computer before every new
recording, but that doesn't happen. I can see that the waitable timer
functions, because my program receives it's signal at the correct time,
as long as the computer does not go into standby. But I want my computer
to wake from standby too.
I have written the following code snippet, that I have found browsing
the net, and adapted to my needs:
SYSTEMTIME sTimeCurrent, sTimeRecord;
GetLocalTime(&sTimeCurrent);
sTimeRecord = sTimeCurrent;
sTimeRecord.wMinute += 1; //Wake up after one minute for this test case
//Convert to a FILETIME
FILETIME fLocalTime;
SystemTimeToFileTime(&sTimeRecord,&fLocalTime);
//Convert from local time to UTC time
//since the system works on UTC internally.
FILETIME fTime;
LocalFileTimeToFileTime(&fLocalTime,&fTime);
//Put time into a LARGE_INTEGER structure
//for the SetWaitableTimer function
LARGE_INTEGER liDueTime;
liDueTime.HighPart = fTime.dwHighDateTime;
liDueTime.LowPart = fTime.dwLowDateTime;
//Create the WaitableTimer
HANDLE hTimer = CreateWaitableTimer(NULL,TRUE,"VideoTimer");
if( hTimer != NULL )
{
CancelWaitableTimer( hTimer );
//Set the timer with the required time. Set the last
//parameter to true to wake up the computer if asleep
if( SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, true ))
{
StandbyPanel->Caption = "Timer has been set!";
//* This executes a thread that uses
//* WaitForSingleObject( hTimer, 90000 );
//* It either updates the StandbyPanel with the current DateTime
//* or gives a failure message after the 90 seconds timeout
mWaitingTest.mExecuteThread( new( HERE ) CWaitingThread( hTimer ));
//* In this example the Panel shows the date time after one minute
//* Thus the signal is received by the thread
//* Set the system to standby and it should wake after 1 minute
SleepEx( 1000, false );
StandbyPanel->Caption = "Going to sleep now!";
//* Here I initiate the Standby mode
//* But when I enable this the computer does not wake at
//* the desired time of one minute
// SetSuspendState( FALSE, FALSE, FALSE );
}
else
{
StandbyPanel->Caption = "Failed to set Timer!";
}
}
else
{
StandbyPanel->Caption = "Failed to create Timer!";
}
What am I missing here? As far as I know this piece of code should work,
but is there something else that has to be done to wake up the computer?
Thanks in advance.
Wiljo.
Technical Details
Message-ID:
<46eaf724$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,dbb9f35f467d4b41,start X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 14 Sep 2007 23:02:40 +0200 From: Wiljo <nospam@nospam.com> User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Can't get the computer to programmatically wake from standby.... (original question in language cpp) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 000774-6, 14-09-2007), Outbound message X-Antivirus-Status: Clean NNTP-Posting-Host: 81.207.96.243 Message-ID: <46eaf724$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1189803812 81.207.96.243 (14 Sep 2007 14:03:32 -0700) Lines: 82 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail