The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ragdog on June 06, 2011, 05:33:30 PM

Title: ElapsedTime crash under WIn7
Post by: ragdog on June 06, 2011, 05:33:30 PM
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
Title: Re: ElapsedTime crash under WIn7
Post by: qWord on June 06, 2011, 06:36:37 PM
Quote from: ragdog on June 06, 2011, 05:33:30 PMunder win xp works fine.
luck!

Quote from: msdnVOID CALLBACK TimerProc (http://msdn.microsoft.com/en-us/library/ms644907(v=vs.85).aspx)(
  __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)
Title: Re: ElapsedTime crash under WIn7
Post by: ragdog on June 06, 2011, 07:39:12 PM
Yes correct it works

Also must if i use a callback without ret ?
Title: Re: ElapsedTime crash under WIn7
Post by: qWord on June 06, 2011, 07:45:13 PM
Quote from: ragdog on June 06, 2011, 07:39:12 PM
Also must if i use a callback without ret ?
:eek
Title: Re: ElapsedTime crash under WIn7
Post by: ragdog on June 06, 2011, 08:04:06 PM
? not

I have remove the ret and it works

invoke StatusTime,hWnd,ecx,eax
    ;ret
CalcElapsedTime ENDP
Title: Re: ElapsedTime crash under WIn7
Post by: qWord on June 06, 2011, 08:22:13 PM
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 (http://www.masm32.com/board/index.php?topic=8654.0) after removing the RET (the LEAVE should also be nop'ed..):
(http://www.masm32.com/board/index.php?action=dlattach;topic=16815.0;id=9351)
What do you think happen here? I'm sure you will get it.

BTW: nice program :U
Title: Re: ElapsedTime crash under WIn7
Post by: ragdog on June 06, 2011, 08:42:11 PM
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
Title: Re: ElapsedTime crash under WIn7
Post by: qWord on June 06, 2011, 09:02:39 PM
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:
Title: Re: ElapsedTime crash under WIn7
Post by: ragdog on June 06, 2011, 09:37:32 PM
Can you send an example?

my programm crash if i set the ret without works it

without using a debugger
Title: Re: ElapsedTime crash under WIn7
Post by: qWord on June 06, 2011, 10:01:11 PM
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
Title: Re: ElapsedTime crash under WIn7
Post by: ragdog on June 06, 2011, 10:48:56 PM
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?!?
Title: Re: ElapsedTime crash under WIn7
Post by: qWord on June 06, 2011, 10:52:40 PM
Quote from: ragdog on June 06, 2011, 10:48:56 PMAll this years wrong?!?
yes...
(e.g. this program (http://www.masm32.com/board/index.php?topic=8654.0))
Title: Re: ElapsedTime crash under WIn7
Post by: ragdog on June 06, 2011, 11:02:20 PM
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