In Windows CE: Suspending a Device I discussed putting the device in suspend. Now let’s look at setting the system to wake using the Real-Time Clock (RTC).
There are several Notify Functions that we can use to wake the system at a given time. In this case, I will use CeRunAppAtTime() to request that the system run an application a few seconds after suspending the system.   This is a handy way to test the suspend and resume functionality of a system.
CeRunAppAtTime() takes two parameters; a string that tells it which application to run and the address of a SYSTEMTIME structure that contains the time to run the application.
Here is an example function that calls CeRunAppAtTime() setting the time to be some seconds in the future:
void SetSleepTime( DWORD SleepSeconds )
                union {
                                LONGLONG time64;
                                FILETIME FT;
                SYSTEMTIME st;
                SystemTimeToFileTime(&st, &SleepTime.FT);
                // We are passed in seconds, but we need to set the
                // wake time in multiples of 100 nanoseconds   
                SleepTime.time64 += (SleepSeconds * 10000000);
                FileTimeToSystemTime(&SleepTime.FT, &st);
                CeRunAppAtTime(TEXT("\\RunAtWake.exe"), &st);
This function gets the current system time, converts it to FILETIME, adds the seconds passed in, and then converts it back to SYSTEMTIME to call CeRunAppAtTime().
So calling this before suspending will cause the system to wake up. The following will wake up in about 20 seconds.
                SetSleepTime( 20 );
                SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE);
Copyright © 2008 – Bruce Eitman
All Rights Reserved