PC wakeup from hibernation using SetWaitableTimer()
-
Having read a number of articles on waking a PC up from hibernation, I have tried to do this using the following code:- hTimer = (HANDLE)CreateWaitableTimer(NULL, TRUE, "My Waitable test Wake Up Timer"); unsigned threadId; HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, &wakeupWatchThread, &hTimer, NULL, &threadId); return TRUE; // return TRUE unless you set the focus to a control The worker thread code is:- unsigned __stdcall wakeupWatchThread(void* dummy) { LARGE_INTEGER lElapse; int i1 = 63000; int i2 = 100000; lElapse.QuadPart = - (i1*i2); // About 10.5 mins elapsed BOOL result = SetWaitableTimer(hTimer, &lElapse, 0, TimerProc, NULL, TRUE); DWORD dwError; if(result == FALSE) dwError = GetLastError(); for (int i = 0; i < 10; i++) SleepEx(INFINITE, TRUE); return 0; } and the timer completion code is :- void CALLBACK TimerProc(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue) { CTime tNow(CTime::GetCurrentTime()); CString szTime, szMsg; szTime = tNow.Format( "%A %H:%M" ); szMsg.Format("Waitable timer expired at %s",szTime); AfxMessageBox(szMsg); } My problem is that the PC doesn't wake up !! (the last parameter of SetWaitableTimer() being set to TRUE should cause the reume from hibernation). When I manual start the PC, the timer has expired. Is there something that I'm not doing ? (Tested on Win2000 Pro only, as this will be the only target system) Doug
-
Having read a number of articles on waking a PC up from hibernation, I have tried to do this using the following code:- hTimer = (HANDLE)CreateWaitableTimer(NULL, TRUE, "My Waitable test Wake Up Timer"); unsigned threadId; HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, &wakeupWatchThread, &hTimer, NULL, &threadId); return TRUE; // return TRUE unless you set the focus to a control The worker thread code is:- unsigned __stdcall wakeupWatchThread(void* dummy) { LARGE_INTEGER lElapse; int i1 = 63000; int i2 = 100000; lElapse.QuadPart = - (i1*i2); // About 10.5 mins elapsed BOOL result = SetWaitableTimer(hTimer, &lElapse, 0, TimerProc, NULL, TRUE); DWORD dwError; if(result == FALSE) dwError = GetLastError(); for (int i = 0; i < 10; i++) SleepEx(INFINITE, TRUE); return 0; } and the timer completion code is :- void CALLBACK TimerProc(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue) { CTime tNow(CTime::GetCurrentTime()); CString szTime, szMsg; szTime = tNow.Format( "%A %H:%M" ); szMsg.Format("Waitable timer expired at %s",szTime); AfxMessageBox(szMsg); } My problem is that the PC doesn't wake up !! (the last parameter of SetWaitableTimer() being set to TRUE should cause the reume from hibernation). When I manual start the PC, the timer has expired. Is there something that I'm not doing ? (Tested on Win2000 Pro only, as this will be the only target system) Doug
Perhaps, I should have emphasised the question in my mind - "Do I have to do anything within the OS (Win2K) to allow the wakeup to occur" ?
Doug