my code like this

invoke SetTimer,NULL,0,1000,offset timerevent
.if eax==0
mov hTimer,eax

In this app, there is no window, and timer can't start to work (callback timerevent).
Posted on 2003-09-29 09:59:31 by optimus
you should be able to get it working without a window, but you must have a messageloop - quoting the PlatformSDK:

An application can process WM_TIMER messages by including a WM_TIMER case statement in the window procedure or by specifying a TimerProc callback function when creating the timer. When you specify a TimerProc callback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER.
Posted on 2003-09-29 10:17:08 by f0dder
probably this is the cause.
my problem, in other word, is that how to use a timer in a nt service program. If dispatching message is required, how to dispatch message with no window?
Posted on 2003-09-29 10:56:11 by optimus
Just run GetMessage, TranslateMessage, DispatchMessage loop without creating any windows? Or use an alternate timer method?
Posted on 2003-09-29 10:58:48 by f0dder
u mean create another thread to do the message loop? will this work?
what is the alternative timer then?
Posted on 2003-09-29 11:07:52 by optimus
one alternative to SetTimer would be creating a thread that does Sleep/timerproc in a loop.
Posted on 2003-09-29 11:14:37 by f0dder
Does Sleep take any CPU time while sleeping?
Posted on 2003-09-29 11:23:42 by optimus
Not really - the thread isn't scheduled until the sleep period is over. Ie, Sleep is _MUCH_ better than whatever manual timeloop you can think of.
Posted on 2003-09-29 11:28:59 by f0dder
yes, the Sleep method is most efficient.
my c2
Posted on 2003-09-29 14:32:16 by Ultrano
but alas does not give very high accuracy... which is what he needs (see other thread - )
Posted on 2003-09-29 14:39:51 by f0dder
I would recommend using Waitable Timers. They are what the Windows task scheduler uses.
Posted on 2003-09-29 20:33:22 by Mecurius
That's sth I've never heard of. :alright:
Posted on 2003-09-29 21:55:06 by optimus