Hi all.

Im unable to make SetTimer to trigger a procedure.
Im sure the timer is up, and i can invoke the procedure ;) , but they wont work together.

;set timer to check
;============

invoke SetTimer, NULL, CHECKTIMER, 10000, addr CheckProc
mov hcheck, eax
.if eax==0 ; si es cero la cagamos
invoke ExitProcess, NULL
.endif

CheckProc proc

invoke MessageBox, NULL, addr msginabottle, addr appname, MB_OK

CheckProc endp

Ah, there is no window, so no hWnd.

Thanks in advance.
I kown this can be a newbie question, but thats what i am.
Posted on 2002-06-07 11:29:20 by bibbo
a time proc is defined like this in msdn
VOID CALLBACK TimerProc(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
);

so you function should be
CheckProc proc hwnd:DWORD, uMSG:DWORD, idEvent:DWORD, dwTime:DWORD

invoke MessageBox, NULL, addr msginabottle, addr appname, MB_OK

CheckProc endp
Posted on 2002-06-07 11:45:19 by Kudos
Is the code directly copied from the program you are writing?

If it is there are several things wrong!
1) Your code will fall past the exit case assuming you set up the timer correctly. There is nothing to stop the code moving past the main body of the code, into the CheckProc function.

2) The CheckProc function does not conform to the prototype specified for a timer callback.
The help document I've got (which is a little old) states:

VOID CALLBACK TimerProc(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
);

You don't have these arguments in your function... This will cause all sorts of stack badness TM to occur.

3) There is no ret in your CheckProc function, this will cause nasty crash type things to happen.

4) There seems to be no loop waiting for the timer event to start... You could in theory simply run the program so quickly it just doesn't have time to hit the timer event!

Mirno
Posted on 2002-06-07 12:00:50 by Mirno
Mirno: what will happen if you dont conform to the callback by using the paramaters that are suppose to be used. you say the stack but does it really do anything bad?

bibbo: here is a little code snipet that works. mirno is probably right when he says there could be a stack issue if you dont use the paramaters the callback is suppose to use.
.586

.model flat, stdcall
option casemap:none

include /masm32/include/windows.inc
include /masm32/include/kernel32.inc
include /masm32/include/user32.inc
includelib /masm32/lib/kernel32.lib
includelib /masm32/lib/user32.lib

TimerProc PROTO

.data
text db "works",0

.code
start:
invoke SetTimer,0,0,800,addr TimerProc


TimerProc proc
invoke MessageBox,0,addr text,0,0
ret
TimerProc endp

invoke ExitProcess,NULL
end start
Posted on 2002-06-07 12:20:12 by smurf
smurf
Your in your code once SetTimer has returned the process will fall thru into TimerProc when it hits the ret it will be jump to what ever is on the stack wich isn't the return address since it wasn't called.


.586
.model flat, stdcall
option casemap:none

include /masm32/include/windows.inc
include /masm32/include/kernel32.inc
include /masm32/include/user32.inc
includelib /masm32/lib/kernel32.lib
includelib /masm32/lib/user32.lib

TimerProc PROTO

.data
text db "works",0

.code
start:
invoke SetTimer,0,0,800,addr TimerProc
.while TRUE
.endw


TimerProc proc
invoke MessageBox,0,addr text,0,0
invoke ExitProcess, 0
ret
TimerProc endp
end start
Posted on 2002-06-07 12:30:01 by Kudos
Thanks to all.

Its all about the procedure declaration.
The code is only a snipet of it. And yes i forgot ret :)
Posted on 2002-06-07 12:32:37 by bibbo
yes good point kudos i wasnt even thinking about it i was just trying to demonstrate for him to at least be able to process his proc and wasnt thinking about the rest of the program.

im still wondering about what kind of corruption i will get without using those parameters in my proc.
Posted on 2002-06-07 12:53:20 by smurf
Well the caller will push the paramaters onto the stack and the proc wont remove them from the stack when it exits, so if the caller has saved something in the stack and tries to pop it it will pop the params that should have been poped by the proc. Also if the proc is called a lot of times it is eventually going to make the stack fill up all available memory.
Posted on 2002-06-07 13:40:06 by Kudos
I tried smurf's code and it seem to work.
But im confused about the parameters of my procedure.

The main purpose of the program is to check for the existence of a program and kill his execution. I dont know if this method (using timered check) is good, or if its a better way to do it (of course). I also dont know how to make and infinite loop that dont consume cpu but this timered thing.

Thanks again.
Posted on 2002-06-07 14:56:32 by bibbo
if you want to pause the process indefinatly maybe
invoke Sleep, INFINITE
Do you mean your program is suposed to check every so offen if a program is running then kill it?
Posted on 2002-06-07 15:28:46 by Kudos
Yes i want to mean that, my english is not good.
Posted on 2002-06-07 15:34:33 by bibbo