News:

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

ElapsedTime crash under WIn7

Started by ragdog, June 06, 2011, 05:33:30 PM

Previous topic - Next topic

ragdog

Hi

I use in my old program calc ElapsedTime now run it under win7 and it crash
i canot find why? under win xp works fine.



.data
szElapsedTime db "%0.2lu:%0.2lu",0

.data?

hInstance   dd ?
szStatusElapsedTime db 100 dup (?)
StartTime     dd ?
ElapsedTime     dd ?
.code
.if uMsg==WM_INITDIALOG
           invoke StatusTime,hWnd,0,0
          mov ElapsedTime,0
       invoke GetTickCount
          mov StartTime,eax
           invoke SetTimer,hWnd,100,1000,offset CalcElapsedTime

StatusTime PROC hWnd:DWORD, Min:DWORD,Sec:DWORD
invoke wsprintf,offset szStatusElapsedTime,
            offset szElapsedTime,Min,Sec
    invoke SetDlgItemText,hWnd,1001,offset szStatusElapsedTime
ret
StatusTime ENDP

CalcElapsedTime PROC uses edx ecx hWnd:DWORD

invoke GetTickCount
mov ecx,StartTime ;Time=EndTime-StartTime
mov StartTime,eax
sub eax,ecx ;eax=Time


add eax,ElapsedTime
xor edx,edx
mov ElapsedTime,eax ;eax=ElapsedTime in miliseconds

mov ecx,1000*60 ;convers miliseconds to minutes & seconds
xor edx,edx
div ecx ;eax=seconds
push eax ;eax=minutes, save it

mov eax,edx ;calc seconds
mov ecx,1000
xor edx,edx
div ecx
pop ecx ;restore minutes
invoke StatusTime,hWnd,ecx,eax

ret
CalcElapsedTime ENDP

qWord

Quote from: ragdog on June 06, 2011, 05:33:30 PMunder win xp works fine.
luck!

Quote from: msdnVOID CALLBACK TimerProc(
  __in  HWND hwnd,
  __in  UINT uMsg,
  __in  UINT_PTR idEvent,
  __in  DWORD dwTime
);

(the first call too it works. However, windows checks the stack and see that it is not balanced - I'm very sure that win7, in opposed to previous versions, purposely call your callback with an invalid return address (=0), thus it crash at RET)
FPU in a trice: SmplMath
It's that simple!

ragdog

Yes correct it works

Also must if i use a callback without ret ?

qWord

FPU in a trice: SmplMath
It's that simple!

ragdog

? not

I have remove the ret and it works

invoke StatusTime,hWnd,ecx,eax
    ;ret
CalcElapsedTime ENDP

qWord

Quote from: ragdog on June 06, 2011, 08:04:06 PM
I have remove the ret and it works

a screen shot from your program after removing the RET (the LEAVE should also be nop'ed..):

What do you think happen here? I'm sure you will get it.

BTW: nice program :U
FPU in a trice: SmplMath
It's that simple!

ragdog

What for a program my fmod example mean you?


Yes i understand it that i  Return from a subroutine back.
But if i remove this under win7 and i have always use for Settimer with callback routine ret

here is the working code without ret


004010D3  /.  55            PUSH EBP
004010D4  |.  8BEC          MOV EBP,ESP
004010D6  |.  52            PUSH EDX
004010D7  |.  51            PUSH ECX
004010D8  |.  E8 47000000   CALL <JMP.&kernel32.GetTickCount>        ; [GetTickCount
004010DD  |.  8B0D 78304000 MOV ECX,DWORD PTR DS:[403078]
004010E3  |.  A3 78304000   MOV DWORD PTR DS:[403078],EAX
004010E8  |.  2BC1          SUB EAX,ECX
004010EA  |.  0305 7C304000 ADD EAX,DWORD PTR DS:[40307C]
004010F0  |.  33D2          XOR EDX,EDX
004010F2  |.  A3 7C304000   MOV DWORD PTR DS:[40307C],EAX
004010F7  |.  B9 60EA0000   MOV ECX,0EA60
004010FC  |.  33D2          XOR EDX,EDX
004010FE  |.  F7F1          DIV ECX
00401100  |.  50            PUSH EAX
00401101  |.  8BC2          MOV EAX,EDX
00401103  |.  B9 E8030000   MOV ECX,3E8
00401108  |.  33D2          XOR EDX,EDX
0040110A  |.  F7F1          DIV ECX
0040110C  |.  59            POP ECX
0040110D  |.  50            PUSH EAX
0040110E  |.  51            PUSH ECX
0040110F  |.  FF75 08       PUSH DWORD PTR SS:[EBP+8]
00401112  |.  E8 8BFFFFFF   CALL 004010A2
00401117  |.  CC            INT3
00401118  |.- FF25 10204000 JMP DWORD PTR DS:[<&kernel32.ExitProcess>;  kernel32.ExitProcess





Now if this question why

qWord

it 'works' because it runs into the INT3. Normally your program should crash if no debugger is used. However, It seem like on Win7 (x64) all callbacks are enclosed by an handler that gets all(or some) exception and continue the program normally. I've recognize this strange behaviour also some time back  in the WndProc while writing some GDI+ programs ...  :boohoo:
FPU in a trice: SmplMath
It's that simple!

ragdog

Can you send an example?

my programm crash if i set the ret without works it

without using a debugger

qWord

instead of
CalcElapsedTime PROC uses edx ecx hWnd:DWORD
use
CalcElapsedTime PROC uses edx ecx hWnd:DWORD,uMsg:DWORD,idEvent:DWORD,dwTime:DWORD
    ...
    ret
CalcElapsedTime endp
FPU in a trice: SmplMath
It's that simple!

ragdog

YEs it works

Now im confused

I have very long used under Windows xp this function for Set a timer Callback ::)

invoke SetTimer,hWnd,100,1000,offset TimerCallback

TimerCallback PROC uses edx ecx hWnd:DWORD

All this years wrong?!?

qWord

FPU in a trice: SmplMath
It's that simple!

ragdog

Yes i know and 3 other projects and xyz Projects

This was for very long time a read mistake  ::)

I thank you qWord  :U

And i have learn it more Read about Api by Msdn :bg