I was about to make a script to change a large amount (+4000) of screwed up TDateTime stamps in a SQL database. The stamps are Start time of recording and stop time which together report duration time. The stop times have been screwed up from DST changes, leaving duration times no longer accurate.
Im using some DLL calls together with lexikos SystemTime class. The problematic thing is when declaring the pointer as a string in AHK it no longer works passing it through the DLLs/class. I get "00000000". Does someone have any idea how to deal with this?
Maybe if getting the floating pointer directly from the SQL DB (still in raw format) and pass it to the DLL or perhaps doing some NumGet/Put or VarSetCapacity on it?
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;oleSt := "41969.4583333333"
dd := "43128.663553"
;stt := SystemTime.Now()
st := SystemTime.FromPointer(dd)
;if (DllCall("oleaut32\SystemTimeToVariantTime", "Ptr", stt.p, "Double*", oleSt))
;MsgBox % oleSt
if (DllCall("oleaut32\VariantTimeToSystemTime", "Ptr", dd, "Double*", st.p))
MsgBox % st.ToString()
; ======================================================================================================================
; Written by Lexikos for EnableUIAccess
/*
SystemTime - Wrapper for Win32 SYSTEMTIME Structure
http://msdn.microsoft.com/en-us/library/ms724950
Usage Examples:
; Create structure from string.
st := SystemTime.FromString(A_Now)
; Shortcut:
st := SystemTime.Now()
; Update values.
st.FromString(A_Now)
; Retrieve components.
year := st.Year
month := st.Month
weekday := st.DayOfWeek
day := st.Day
hour := st.Hour
minute := st.Minute
second := st.Second
ms := st.Milliseconds
; Set or perform math on component.
st.Year += 10
; Create structure to receive output from DllCall.
st := new SystemTime
DllCall("GetSystemTime", "ptr", st.p)
MsgBox % st.ToString()
; Fill external structure.
st := SystemTime.FromPointer(externalPointer)
st.FromString(A_Now)
; Convert external structure to string.
MsgBox % SystemTime.ToString(externalPointer)
*/
class SystemTime
{
FromString(str)
{
if this.p
st := this
else
st := new this
if !(p := st.p)
return 0
FormatTime wday, %str%, WDay
wday -= 1
FormatTime str, %str%, yyyy M '%wday%' d H m s '0'
Loop Parse, str, %A_Space%
NumPut(A_LoopField, p+(A_Index-1)*2, "ushort")
return st
}
FromPointer(pointer)
{
return { p: pointer, base: this } ; Does not call __New.
}
ToString(st = 0)
{
if !(p := (st ? (IsObject(st) ? st.p : st) : this.p))
return ""
VarSetCapacity(s, 28), s := SubStr("000" NumGet(p+0, "ushort"), -3)
Loop 6
if A_Index != 2
s .= SubStr("0" NumGet(p+A_Index*2, "ushort"), -1)
return s
}
Now()
{
return this.FromString(A_Now)
}
__New()
{
if !(this.SetCapacity("struct", 16))
|| !(this.p := this.GetAddress("struct"))
return 0
NumPut(0, NumPut(0, this.p, "int64"), "int64")
}
__GetSet(name, value="")
{
static fields := {Year:0, Month:2, DayOfWeek:4, Day:6, Hour:8
, Minute:10, Second:12, Milliseconds:14}
if fields.HasKey(name)
return value=""
? NumGet( this.p + fields[name], "ushort")
: NumPut(value, this.p + fields[name], "ushort")
}
static __Get := SystemTime.__GetSet
static __Set := SystemTime.__GetSet
}