News:

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

Local date & time

Started by ThexDarksider, September 27, 2009, 02:45:30 AM

Previous topic - Next topic

ThexDarksider

Hi, I'm trying to get local date & time. Actually I'm trying with seconds first.

This is my code so far:

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\msvcrt.inc
includelib \masm32\lib\msvcrt.lib
include \masm32\macros\macros.asm
.code
start:
main proc
local ltime:SYSTEMTIME
local lsecond:DWORD
local lol
invoke GetLocalTime,addr ltime
movzx eax,ltime.wSecond
mov lsecond,ustr$(eax)
invoke MessageBoxA,NULL,addr lsecond,NULL,MB_OK
invoke ExitProcess,0
main endp
end start


It assembles and links normally, but displays an empty message box. What's wrong? :(

Btw it's 5 AM, I'm tired... I'll check back in a couple of hours.

2-Bit Chip

#1
.386
.model flat, stdcall
option casemap: none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\msvcrt.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\msvcrt.lib

include \masm32\macros\macros.asm

.code

_main proc
    LOCAL ltime:SYSTEMTIME
    LOCAL lsecond:DWORD
    ;LOCAL lol
   
    invoke GetLocalTime, ADDR ltime
    movzx eax, ltime.wSecond
   
    invoke MessageBox, NULL, ustr$(eax), NULL, MB_OK

    invoke ExitProcess, 0

_main endp

end _main


You are passing an address of an address that points to a null-terminated string.

mov lsecond,ustr$(eax) ; lsecond = *strSecond
invoke MessageBoxA,NULL,addr lsecond,NULL,MB_OK ; Then you're passing a pointer of *strSecond = **strSecond

ThexDarksider

So if I want to store it to the variable and use later, I should use:

mov lsecond,ustr$(eax)
invoke MessageBoxA,NULL,lsecond,NULL,MB_OK


Am I right?

herge

#3
 Hi *.*:

; SHOWTIME.ASM Friday, June 19, 2009 8:50 PM     
; by herge- Show System Date & Time
.XCREF
.XLIST
; XCREF = NO cross Reference
; XLIST = NO listing - Windows.inc is kind of massive man!
include \masm32\include\masm32rt.inc
.LIST
.CREF
.data
stm  SYSTEMTIME<>
    org stm; Must be eight words
wYear    dw 0
wMonth   dw 0
wToDay   dw 0 ; Sunday 0 to Saturday 6
wDay     dw 0
wHour    dw 0
wMinute  dw 0
wSecond  dw 0
wKsecond dw 0
date_buf   db 260 dup (32) ; 32 is 20 hex Which is a ASCII Space
time_buf   db 20 dup (32)
           db 0
dateformat db " dddd, MMMM, dd, yyyy", 0
timeformat db "hh:mm tt",0
.code
Start:
;  invoke   GetLocalTime, addr stm
;  invoke   GetDateFormat, 0, 0, \
;           ADDR stm, ADDR dateformat, ADDR date_buf, 260
   invoke   GetDateFormat, 0, 0, \
            0, ADDR dateformat, ADDR date_buf, 60
   mov   ecx, offset date_buf
   add   ecx, eax; add length returned by GetDateFormat
   mov   byte ptr [ecx-1], " " ;replace null with space
   invoke   GetTimeFormat, 0, 0, \
            0, ADDR timeformat, ecx, 20
   invoke   MessageBox, 0, addr date_buf, addr date_buf, MB_OK
   invoke   ExitProcess, 0 ; Call Exit return to DOS or
;                                          God Forbid Windows!
;
end Start; The Specified Entry point is Start
;
; Last Line F:\masm32\bin\ShowTime.asm



regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

herge

 Hi *.*:

Backwards:


; BACKTIME.ASM Friday, October 02, 2009 5:56:39 AM     
; by Herge - Show System Date & Time
.XCREF
.XLIST
; XCREF = NO cross Reference
; XLIST = NO listing - Windows.inc is kind of massive man!
include \masm32\include\masm32rt.inc
.LIST
.CREF
.data
stm  SYSTEMTIME<>
    org stm; Must be eight words
wYear    dw 0
wMonth   dw 0
wToDay   dw 0 ; Sunday 0 to Saturday 6
wDay     dw 0
wHour    dw 0
wMinute  dw 0
wSecond  dw 0
wKsecond dw 0
date_buf   db 260 dup (32) ; 32 is 20 hex Which is a ASCII Space
time_buf   db 20 dup (32)
           db 0
dateformat db " dddd, MMMM, dd, yyyy", 0
timeformat db "ss:mm$hh tt",0 ;; Changed HERE
.code
Start:
;  invoke   GetLocalTime, addr stm
;  invoke   GetDateFormat, 0, 0, \
;           ADDR stm, ADDR dateformat, ADDR date_buf, 260
   invoke   GetDateFormat, 0, 0, \
            0, ADDR dateformat, ADDR date_buf, 60
   mov   ecx, offset date_buf
   add   ecx, eax; add length returned by GetDateFormat
   mov   byte ptr [ecx-1], " " ;replace null with space
   invoke   GetTimeFormat, 0, 0, \
            0, ADDR timeformat, ecx, 20
   invoke   MessageBox, 0, addr date_buf, addr date_buf, MB_OK
   invoke   ExitProcess, 0 ; Call Exit return to DOS or
;                                          God Forbid Windows!
;
end Start; The Specified Entry point is Start
;
; Last Line F:\masm32\bin\BackTime.asm




Will this do the job!

Regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy