SetTimer and timerProc callback ? 
Author Message
 SetTimer and timerProc callback ?

There is a thread a few days back named

'SetTimer' : cannot convert parameter 4 from 'void .... ?

One of the responders, Igor, has posted the following:

But of course. Now you are running into the same problem SetTimer has run into earlier - a static callback does not know which
instance it is supposed to work for. If you only ever expect one instance, save it in the global variable. Otherwise, you will
need to maintain some kind of mapping of timer IDs (as returned by SetTimer) to instances

My question is : wouldn't it be simpler, instead of "maintaining some kind of mapping
of timer id's to instances' to simply use a global which is not static, that way each
instant will have it's own global ?

Tia.



Fri, 29 Apr 2005 06:34:27 GMT  
 SetTimer and timerProc callback ?
[watch your line length - 72 columns is preferred]

Quote:

> There is a thread a few days back named

> 'SetTimer' : cannot convert parameter 4 from 'void .... ?

> One of the responders, Igor, has posted the following:

> But of course. Now you are running into the same problem SetTimer has run into earlier - a static callback does not know which
> instance it is supposed to work for. If you only ever expect one instance, save it in the global variable. Otherwise, you will
> need to maintain some kind of mapping of timer IDs (as returned by SetTimer) to instances

> My question is : wouldn't it be simpler, instead of "maintaining some kind of mapping
> of timer id's to instances' to simply use a global which is not static, that way each
> instant will have it's own global ?

But, for multiple instances of a class from one dll, each instance
CANNOT have its own global (it is, after all, a global).  Some kind
of mapping is required.

--
Craig Powers
MVP - Visual C++



Fri, 29 Apr 2005 22:53:10 GMT  
 SetTimer and timerProc callback ?

Quote:
> My question is : wouldn't it be simpler, instead of "maintaining some
kind of mapping
> of timer id's to instances' to simply use a global which is not

static, that way each

Quote:
> instant will have it's own global ?

And how, pray tell, would you declare a global variable in such a way
that each instance has its own copy? Care to demonstate a fragment of
code?
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Fri, 29 Apr 2005 23:54:07 GMT  
 SetTimer and timerProc callback ?

Quote:
> Is it not the case that every time a new object is created we get a
new
> set of globals?

Of course not. You get a new set of non-static data members. And to
access those, you need a 'this' pointer of an appropriate instance.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Sat, 30 Apr 2005 05:50:17 GMT  
 SetTimer and timerProc callback ?
I am referring to the default model that we get from the wizard when
we choose "Simple Object".
Is it not the case that every time a new object is created we get a new
set of globals?
Quote:



> > My question is : wouldn't it be simpler, instead of "maintaining some
> kind of mapping
> > of timer id's to instances' to simply use a global which is not
> static, that way each
> > instant will have it's own global ?

> And how, pray tell, would you declare a global variable in such a way
> that each instance has its own copy? Care to demonstate a fragment of
> code?
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



Sat, 30 Apr 2005 04:04:19 GMT  
 SetTimer and timerProc callback ?

Quote:

> I am referring to the default model that we get from the wizard when
> we choose "Simple Object".
> Is it not the case that every time a new object is created we get a new
> set of globals?

No.  You only get a new set of globals for a new instance of your
server.  If it's in-process, that means that each program instance
that uses it will get new instances.  If it's out-of-process, that
means that each time you restart it you will get new instances.

--
Craig Powers
MVP - Visual C++



Sat, 30 Apr 2005 06:23:42 GMT  
 SetTimer and timerProc callback ?

Quote:



> > Is it not the case that every time a new object is created we get a
> new
> > set of globals?

> Of course not. You get a new set of non-static data members. And to

what if the global was *not* static ?
Quote:
> access those, you need a 'this' pointer of an appropriate instance.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



Sat, 30 Apr 2005 08:31:00 GMT  
 SetTimer and timerProc callback ?

Quote:




Quote:


> > > Is it not the case that every time a new object is created we get
a
> > new
> > > set of globals?

> > Of course not. You get a new set of non-static data members. And to

> what if the global was *not* static ?

What if it was not? You get one copy of any global or static variable or
a static data member per process. You get a copy of any non-static data
member per instance of the class it is a member of.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Sat, 30 Apr 2005 08:57:36 GMT  
 SetTimer and timerProc callback ?
Yes, you are right, I have just tested this, and changing a glob1
in obj1 will change glob1 in obj2.
Thanks!!!
Quote:



> > Is it not the case that every time a new object is created we get a
> new
> > set of globals?

> Of course not. You get a new set of non-static data members. And to
> access those, you need a 'this' pointer of an appropriate instance.
> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



Sat, 30 Apr 2005 08:50:02 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Problem with calling TimerProc with SetTimer()?????

2. TimerProc Callback as argument ...

3. TimerProc callback - 2nd go!

4. Thread violation from SetTimer() callback

5. ? SetTimer callback function

6. CALLBACK, CALLBACK, CALLBACK?

7. Help with SetTimer or CWnd::SetTimer

8. TimerProc

9. Using a member function as a TimerProc?

10. Help please with Timerproc coding problem

11. TimerProc

12. non static member ftn as TimerProc ???

 

 
Powered by phpBB® Forum Software