News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

FILETIME<> to SYSTEMTIME<>

Started by Mark Jones, February 28, 2005, 08:34:24 PM

Previous topic - Next topic

Mark Jones

Hi. I'm a bit baffled by some apparent conversion anomalies between these two. Long story short I thought that a great way of protecting my app would be for it to read it's own file-modified date and time, and compare that with a filetime value written to itself after compilation. This is tricky but it works! However, during testing I ran into a strange issue. I converted the filetime into a system time and tried displaying it. The result is wrong and I can't figure out why. Here is the relevant code:


.data?
pFiletime  FILETIME<> ; contains any filetime data, see below
pSystemTime SYSTEMTIME<>

.data
szTmp db 64 dup(0) ; result buffer
szCaption db "Converted FileTime:",0

.code
; for testing, lets just make pFileTime a known date/time
; 000000: 74 85 C9 27 BA 1B C5 01
mov pFileTime.dwHighDateTime, 01C51BBAh   ; 2005/02/25
mov pFileTime.dwLowDateTime, 27C98574h   ; 11:17:59pm

    Invoke FileTimeToSystemTime, Addr pFileTime, Addr pSystemTime

    mov eax,0
    movsx eax, pSystemTime.wMinute ; all are word values
    push eax
    movsx eax, pSystemTime.wHour
    push eax
    movsx eax, pSystemTime.wDay
    push eax
    movsx eax, pSystemTime.wMonth
    push eax
    movsx eax, pSystemTime.wYear
    push eax
   
szText szTimeFormat, "%04u/%02u/%02u, %02u:%02u",0 ; 2005/02/25, 23:17
    push offset szTimeFormat
    lea eax, szTmp
    push eax
    call wsprintf   ; line might be too long to INVOKE

    invoke MessageBox,0,addr szCaption,addr szTmp,MB_OK ; display incorrect!


What happens is the correct year, month, and minute is displayed, but the day is always +1 and the hour is always 04. Printing the word values pSystemTime.wDay and pSystemTime.wHour also shows the same values. Why are these always incorrect? Thanks for any insight.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Petroizki

Nothing wrong there.

BUT, the time you have given is in GMT time, you must use FileTimeToLocalFileTime to get it in your machine time. :eek


.data?
pLocalFileTime FILETIME <?>
...
.code
invoke FileTimeToLocalFileTime, ADDR pFileTime, ADDR pLocalFileTime
invoke FileTimeToSystemTime, ADDR pLocalFileTime, ADDR pSystemTime



confusing, isn't it..  :lol

Mark Jones

 ..Omg, I must be dumb! :lol :red

Thanks for the well-needed eye-opening. :U
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08