10 messages in net.java.dev.jna.usersKernel32 Waking Hibernating Machine
FromSent OnAttachments
Dale...@coats.comApr 24, 2008 6:34 pm 
Dale...@coats.comApr 28, 2008 5:01 pm 
Timothy WallApr 29, 2008 10:13 am 
Dale...@coats.comApr 30, 2008 9:24 am 
Dale...@coats.comApr 30, 2008 10:10 am 
Timothy WallMay 1, 2008 5:58 am 
Dale...@coats.comMay 1, 2008 7:37 am 
Timothy WallMay 1, 2008 8:07 am 
Timothy WallMay 1, 2008 8:35 am 
Dale...@coats.comMay 1, 2008 10:12 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Kernel32 Waking Hibernating MachineActions...
From:Dale...@coats.com (Dale@coats.com)
Date:Apr 24, 2008 6:34:42 pm
List:net.java.dev.jna.users

I did what I thought should work, but the machine doesn't wake-up. I know this isn't a windows help forum, but in case I'm screwing something up in the JNA bit, I thought I'd post. Or I could get really lucky and find someone here who's done this wake-up thing before!

I've got some code working that prints timestamp one and timestamp two.  They print 5 minutes apart using SetWaitableTimer. So far so good.

long aTime = -600000000; // Windows screwball minute long aDuration = 0; System.out.println("wait 5 minutes"); long aDuration = aTime * 5; FILETIME pDueTime = new FILETIME(); pDueTime.dwHighDateTime = (int)(aDuration >> 32); pDueTime.dwLowDateTime = (int)(0xFFFFFFFF & aDuration); HANDLE htimer = kernel32.CreateWaitableTimer(null, true, "MyWaitableTimer" + Math.random()); boolean setTimerResult = kernel32.SetWaitableTimer(htimer, pDueTime, 0L, null, null, true); if (setTimerResult){ System.out.println(new Date() + " The timer has been set. Waiting."); int waitResult = kernel32.WaitForSingleObject(htimer, Integer.MAX_VALUE); System.out.println(new Date() + " The wait has ended with " + waitResult); kernel32.CloseHandle(htimer); } else {throw new Exception("The timer set failed ");} kernel32.CloseHandle(htimer);

My Kernel32 stuff is at the bottom of the post.

The last parameter of SetWaitableTimer set to true means the machine is supposed to wake from hibernate or suspend when the timer fires. But if I hibernate my machine after I see timestamp one print out, the machine does not wake-up to print timestamp two.

If I manually resume my machine, it prints timestamp two but of the difference between the two timestamps is greater than 5 minutes (depending on how long I wait to do the manual resume). I have read the references, below, but I must be missing something.  Should the above code work to resume a machine, or do I need to do something else?

--Dale--

References: SetWaitbleTimer http://msdn2.microsoft.com/en-us/library/ms686289(VS.85).aspx WaitForSingleObject http://msdn2.microsoft.com/en-us/library/ms687032.aspx Using Waitable Timer Objects http://msdn2.microsoft.com/en-us/library/ms687008(VS.85).aspx

My Kernel32 Additions with MSDN API comments: /* * HANDLE WINAPI CreateWaitableTimer( * __in_opt LPSECURITY_ATTRIBUTES lpTimerAttributes, * __in BOOL bManualReset, * __in_opt LPCTSTR lpTimerName * ); */

HANDLE CreateWaitableTimer(SECURITY_ATTRIBUTES lpTimerAttributes, boolean bManualReset, String lpTimerName);

/* * typedef struct _SECURITY_ATTRIBUTES { * DWORD nLength; * LPVOID lpSecurityDescriptor; * BOOL bInheritHandle; * } SECURITY_ATTRIBUTES, * *PSECURITY_ATTRIBUTES, * *LPSECURITY_ATTRIBUTES; */

public static class SECURITY_ATTRIBUTES extends Structure { public int nLength = size(); public Pointer lpSecurityDescriptor; public boolean bInheritHandle; }

//============================================================================================= /* * BOOL WINAPI SetWaitableTimer( * __in HANDLE hTimer, * __in const LARGE_INTEGER* pDueTime, * __in LONG lPeriod, * __in_opt PTIMERAPCROUTINE pfnCompletionRoutine, * __in_opt LPVOID lpArgToCompletionRoutine, * __in BOOL fResume * ); */

boolean SetWaitableTimer(HANDLE htimer, FILETIME pDueTime, long lPeriod, Pointer pfnCompletionRoutine, Pointer lpArgToCompletionRoutine, boolean fResume);

/* * typedef struct _FILETIME { * DWORD dwLowDateTime; * DWORD dwHighDateTime; * } FILETIME, * *PFILETIME; */

public static class FILETIME extends Structure { public int dwLowDateTime = size(); public int dwHighDateTime = size(); }

//============================================================================================= /* * DWORD WINAPI WaitForSingleObject( * __in HANDLE hHandle, * __in DWORD dwMilliseconds * ); */ int WaitForSingleObject(HANDLE hHandle, int dwMilliseconds);

//============================================================================================= /* * BOOL WINAPI CloseHandle( * __in HANDLE hObject * ); */ boolean CloseHandle(HANDLE hObject);