 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Micahs Guest
|
Posted: Thu Nov 16, 2006 2:39 am Post subject: dllcall -> SetWaitableTimer (works in xp but not in win98 |
|
|
@Boskoop
@all
Boskoop originally posted this code to resume from suspend at a certain time. It works perfectly in xp, but in 98 it executes the code after the line:
| Code: | | WakeUp(Year, Month, Day, Hour, Minute, Hibernate, Resume, Name) | immediately - with no timed delay. Anyone have any ideas?
Thanks, Micahs
Here is the code again. For testing purposes I added some code to set the target date 1 minute into the future.
| Code: |
; CONFIGURATION
Year=2006
Month=11 ;1-12
Day=14 ;1-31
Hour=21 ;0-23
Minute=16 ;1-59
Hibernate=0 ;0, 1, 2
Resume=1 ;0,1
Name=%A_Now%
;***********************added for testing
EnvAdd,Name,1,Minutes
StringMid,Year,Name,1,4
StringMid,Month,Name,5,2
StringMid,Day,Name,7,2
StringMid,Hour,Name,9,2
StringMid,Minute,Name,11,2
;msgbox, %Name%`n%Year%-%Month%-%Day%-%Hour%-%Minute%
;*************************************
; AUTOEXECUTE
WakeUp(Year, Month, Day, Hour, Minute, Hibernate, Resume, Name)
msgbox, I'm awake and working!
; FUNCTIONS
WakeUp(Year, Month, Day, Hour, Minute, Hibernate, Resume, Name)
;Awaits duetime, then returns to the caller (like some sort of "sleep until duetime").
;If the computer is in hibernate or suspend mode
;at duetime, it will be reactivated (hardware support provided)
;Parameters: Year, Month, Day, Hour, Minute together produce duetime
;Hibernate: If Hibernate=1, the function hibernates the computer. If Hibernate=2 the computer is set to
; suspend-mode
;Resume: If Resume=1, the system is restored from power save mode at due time
;Name: Arbitrary name for the timer
{
duetime:=GetUTCFileTime(Year, Month, Day, Hour, Minute)
Handle:=DLLCall("CreateWaitableTimer"
,"char *", 0
,"Int",0
,"Str",name, "UInt")
DLLCall("CancelWaitableTimer","UInt",handle)
DLLCall("SetWaitableTimer"
,"Uint", handle
,"Int64*", duetime ;duetime must be in UTC-file-time format!
,"Int", 1000
,"Uint",0
,"Uint",0
,"Int",resume)
;Hibernates the computer, depending on variable "Hibernate":
If Hibernate=1 ;Hibernate
{
DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
}
If Hibernate=2 ;Suspend
{
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
}
Signal:=DLLCall("WaitForSingleObject"
,"Uint", handle
,"Uint",-1)
DllCall("CloseHandle", Uint, Handle) ;Closes the handle
}
GetUTCFiletime(Year, Month, Day, Hour, Min)
;Converts "System Time" (readable time format) to "UTC File Time" (number of 100-nanosecond intervals since January 1, 1601 in Coordinated Universal Time UTC)
{
DayOfWeek=0
Second=00
Millisecond=00
;Converts System Time to Local File Time:
VarSetCapacity(MyFiletime , 64, 0)
VarSetCapacity(MySystemtime, 32, 0)
InsertInteger(Year, MySystemtime,0)
InsertInteger(Month, MySystemtime,2)
InsertInteger(DayOfWeek, MySystemtime,4)
InsertInteger(Day, MySystemtime,6)
InsertInteger(Hour, MySystemtime,8)
InsertInteger(Min, MySystemtime,10)
InsertInteger(Second, MySystemtime,12)
InsertInteger(Millisecond,MySystemtime,14)
DllCall("SystemTimeToFileTime", Str, MySystemtime, UInt, &MyFiletime)
LocalFiletime := ExtractInteger(MyFiletime, 0, false, 8)
;Converts local file time to a file time based on the Coordinated Universal Time (UTC):
VarSetCapacity(MyUTCFiletime , 64, 0)
DllCall("LocalFileTimeToFileTime", Str, MyFiletime, UInt, &MyUTCFiletime)
UTCFiletime := ExtractInteger(MyUTCFiletime, 0, false, 8)
Return UTCFileTime
}
ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 32)
; Documented in Autohotkey Help
{
Loop %pSize%
result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
return result
return -(0xFFFFFFFF - result + 1)
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; Documentated in Autohotkey Help
{
Loop %pSize%
DllCall("RtlFillMemory", UInt, &pDest + pOffset + A_Index-1
, UInt, 1, UChar, pInteger >> 8*(A_Index-1) & 0xFF)
}
|
|
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Sun Mar 11, 2007 10:24 am Post subject: |
|
|
Any idea how to schedule (eg. every Tuesday, 20:15-21:15 --> VCR) the above code?
Windows Scheduler?
The script as a service?
 |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Sun Mar 11, 2007 10:48 pm Post subject: |
|
|
| MSDN wrote: | | SetSuspendState: Client Requires Windows Vista, Windows XP, or Windows 2000 Professional. | Sic... _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 460
|
Posted: Mon Mar 12, 2007 6:40 am Post subject: |
|
|
@PhiLho
Thanks for the reply! In my implementation, 'hibernate' is set to '0' so 'SetSuspendState' is never executed. It looks like it is 'SetWaitableTimer' that's not working - it just blows on past and doesn't wait like it should. In win98 that is. In XP it works great. MSDN states that 'SetWaitableTimer' will work in 98 with a unicode patch, but not for me. Oh well.
Just now, reading Boskoop's orig thread (http://www.autohotkey.com/forum/viewtopic.php?t=12281) I see
| Quote: | | Wake up from Hibernate requires hardware support for S4-mode | Hmm, maybe the 'puter I was using didn't support this.
[EDIT] - Again, Hmm. After reading Boskoop's latest post, my question has been answered.
@bobo
When I couldn't get it to work in win98 I stopped working on this, but now I'll post it for posterity.
Try this:
http://www.autohotkey.net/~Micahs/sndSched/sndSched.zip
It lets you create timers that reprogram themselves for the next cycle after firing. It also lets you moniter and kill individual timers. I haven't cleaned this up or commented very thoroughly. Right now, it only supports Weekdays, Weekends, or Everyday. I was going to add specific days, but I stopped working on it. It won't take much to add that feature. Have fun!
[EDIT] - Also, it currently only plays sounds, but it shouldn't be hard to make it execute a program or such. (Or kill a program)
For VCR functionality, I would leave it the way it is for scheduling start time, and when it fires:
| Code: | ;call to sleep until awoken
WakeUp(YYYY, MM, DD, Hour, Min, Resume, Name)
;^sleeps for specified time^
;does this once it wakes up \/
;do stuff to start whatever I want
;use wakeup data to reconstruct start time
Start = %YYYY%%MM%%DD%%Hour%%Min%%Sec%
;create stop time in the YYYYMMDDHH24MISS format
Stop = %stopYYYY%%stopMM%%stopDD%%stopHour%%stopMin%%stopSec%
;get difference between start time and stop time in seconds
StartStopDiff := EnvSub, %Stop%, %Start%, Seconds
;set timer for desired stop time
SetTimer,stopIT,%StartStopDiff%
Return
stopIT:
;do stuff to stop whatever I started
;continue - If recurring, set for next time. If not, exit
title=%newTitle%
if(recurring=1)
{ EnvAdd, Var, 1, Days
gosub dateFixer
gosub makeLNK
goto reDeaux
}
else
{ exitApp
}
Return |
You could stick this in the 'FirstCall.ahk' module replacing lines 44-69. This is untested, but looks ok. You just have to provide the 'Stop' data, maybe add another date-time picker section in the gui.
Of course, you'll have to make other changes too. :) _________________

Last edited by Micahs on Mon Mar 12, 2007 8:59 am; edited 1 time in total |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Mon Mar 12, 2007 7:39 am Post subject: |
|
|
Click it to get it  |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 460
|
Posted: Mon Mar 12, 2007 9:14 am Post subject: |
|
|
Erbärmlicher mann, ich sprechen Deutsch nicht! - FreeTranslation.com _________________
 |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Mon Mar 12, 2007 9:45 am Post subject: |
|
|
Nice translation.
Sorry. FYI, I've linked that image just to show what I'm looking for. You must know that I didn't seen the image you've posted in advance. And I'm really sorry that the linked app/site is in German. Well, 80 Mill. Germans don't have a problem with that (and there's a bunch of people from Austria&Switzerland too ) so it wasn't completely useless.
Anyway, thanks for your statement & support.  |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 460
|
Posted: Fri Mar 16, 2007 8:04 pm Post subject: |
|
|
Yeah, I translated it back to english and was amused by the results so I posted it anyway.
| Quote: | | 80 Mill. Germans don't have a problem with that | Sorry, dude. Wasn't knockin' it...
| Quote: | | I didn't seen the image you've posted in advance | Yeah, I posted and then edited right after. Your post came right in the middle. Serves you right for being so efficient!  |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 460
|
Posted: Thu Apr 05, 2007 5:42 am Post subject: |
|
|
This has been solved (but still doesn't work). The "RtlFillMemory" function does not work in 98. _________________
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|