I use key word "GetDateFormat" to Search.
I found this example.
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
szTime db "00:00:00", 0 ; time mask
.code
start:
invoke GetTimeFormat,0,TIME_FORCE24HOURFORMAT,0,0,
addr szTime,9 ; get current time
invoke MessageBox, 0, addr szTime, 0, 0
invoke ExitProcess,NULL
end start
but it just "00:00:00"
How to get time & date and show it ?
I found this example.
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
szTime db "00:00:00", 0 ; time mask
.code
start:
invoke GetTimeFormat,0,TIME_FORCE24HOURFORMAT,0,0,
addr szTime,9 ; get current time
invoke MessageBox, 0, addr szTime, 0, 0
invoke ExitProcess,NULL
end start
but it just "00:00:00"
How to get time & date and show it ?
You are getting your default time (that you initialised your buffer to), because the buffer you have supplied to the API is too small. You should call the function twice: the first time with a zero length buffer, this will fail, and the API will return the required buffer size in eax. Then you allocate a buffer of the same size as indicated by eax. Then you recall the function with the new buffer, the API will happily fill it.
That code works for me.
thanks.
Now I get it.
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
stm SYSTEMTIME<>
dateformat db "dd:MM:yyyy",0
buffer db 100 dup (0)
.code
start:
invoke GetLocalTime, addr stm
invoke GetDateFormat, LOCALE_USER_DEFAULT, NULL, \
addr stm,addr dateformat, addr buffer, sizeof buffer
invoke MessageBox, 0, addr buffer, NULL, MB_OK
invoke ExitProcess,NULL
end start
Now I get it.
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
stm SYSTEMTIME<>
dateformat db "dd:MM:yyyy",0
buffer db 100 dup (0)
.code
start:
invoke GetLocalTime, addr stm
invoke GetDateFormat, LOCALE_USER_DEFAULT, NULL, \
addr stm,addr dateformat, addr buffer, sizeof buffer
invoke MessageBox, 0, addr buffer, NULL, MB_OK
invoke ExitProcess,NULL
end start
Another question!
How to add or sub wYear,wMonth,wDay?
.code
start:
invoke GetLocalTime, addr stm
ASSUME edi: PTR SYSTEMTIME ;?
mov edi,offset stm ;?
mov ax,.wYear ;?
sub ax,1 ;?
mov .wYear,ax ;?
invoke MessageBox, 0, addr stm.wYear, NULL, MB_OK ;?
How to add or sub wYear,wMonth,wDay?
.code
start:
invoke GetLocalTime, addr stm
ASSUME edi: PTR SYSTEMTIME ;?
mov edi,offset stm ;?
mov ax,.wYear ;?
sub ax,1 ;?
mov .wYear,ax ;?
invoke MessageBox, 0, addr stm.wYear, NULL, MB_OK ;?
How about this:
[size=12]
.code
start:
invoke GetLocalTime, addr stm
ASSUME edi :PTR SYSTEMTIME
lea edi, stm
sub [edi].wYear, 1
invoke MessageBox, 0, addr stm.wYear, NULL, MB_OK
assume edi :nothing
[/size]
wYear is not a string, I suggest you don't push it for MessageBox.
wYear is not a string, I suggest you don't push it for MessageBox.
Oops, i forgot about that too. I obviously spend too much time in HLLs that implicitly do the conversion for you :/