Using GetTickCount API, I just tried to display it through a MessageBox.
.But, i got only garbage values.
Please tell me,What foolishness i done it in the code,( following below).


.data
mSeconds db ?
szTitle db "My Attempts",13,10,0

.code

invoke GetTickCount ;Get the Tick Count in MilliSeconds.
mov dword ptr [ mSeconds],eax ;think the result is in eax.

invoke MessageBoxA,0,ADDR mSeconds, ADDR szTitle, MB_OK ; Display It
invoke ExitProcess, 0 ; Leave the program
Posted on 2003-10-09 18:51:30 by zakham
Hi,

First of all: since the return value of GetTickCount is a dword, you have to convert it to a displayable string. The next problem is - you're trying to store the result of GetTickCount in a reserved, byte-sized memory location (mSeconds), so it does overwrite the title of message box (szTitle).

BTW. Is ADDR used for the addresses known at compile time too? Or should it be rather an OFFSET?

Regards, Mikael
Posted on 2003-10-09 20:10:45 by MikaelC
Hi :)

@zakham: I think this should work... (you need to include masm32.lib):
.data

szTitle db "My Attempts",13,10,0
[b]szSeconds db 20 dup (0)[/b]

.code

invoke GetTickCount ;Get the Tick Count in MilliSeconds.
[b]invoke dwtoa,eax,offset szSeconds[/b]
invoke MessageBoxA,0,offset szSeconds, offset szTitle, MB_OK ; Display It
invoke ExitProcess, 0 ; Leave the program


@MikaelC:
The ADDR macro only works from within INVOKE. It is exactly the same as OFFSET, except when it's a local variable in wich case it assembles this:
lea eax,[ebp + something]    ;Put the address in EAX

push eax ;Push it, as it is a parameter for INVOKE

The only drawback is that ADDR does not work on a label that was not already defined. OFFSET works with any label as long as it is static (i.e. known at assembly time).
Posted on 2003-10-09 21:31:35 by QvasiModo
@QvasiModo:
Well - I know the way ADDR works and assembles, I wasn't sure if it could be used for static data also.

Cheers.
Posted on 2003-10-10 02:31:42 by MikaelC
Generally I would only use the addr when the variable I am using is a local variable (ie part of the stack). For the rest of the variables, I would just use offset.
Posted on 2003-10-10 03:52:56 by roticv