Link to home
Start Free TrialLog in
Avatar of rhoepperger
rhoepperger

asked on

Class-member-function as TimerProc

Hi,

I can't figure out how to set a timer so
that it calls a member-function of my
class.  

class SomeClass
{
   public:
   void CALLBACK EXPORT MyTimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime);
   void SomeFunction();
}

void SomeClass::SomeFunction()
{
   SetTimer(...,MyTimerProc);  // << error C2664
}

Currently all I can do is to use a
global, - non-class-member-function
but I need to have access to my class'es
variables when the timer-event occurs.

My problem is that when I try to use
a class-member-function in my SetTimer-
call then the compiler (VC 5.0) refuses
with:
error C2664:
'SetTimer' : cannot convert parameter 4 from 'void (struct HWND__ *,unsigned int,unsigned int,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'


Basically I want to stay "within" my
class with the TimerProc.  Seemingly
I need a cast of some sort.

How can I do that ?  Any help greatly appreciated !  Thanks a lot !
Richard
ASKER CERTIFIED SOLUTION
Avatar of ufolk123
ufolk123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rhoepperger
rhoepperger

ASKER

Thanks a lot.  Good solution.
But I just came up with another solution:

MMRESULT mmres=timeSetEvent(1000, 100, TimeProc, (DWORD) this, TIME_PERIODIC);

Multimedia-Timers accept a user-argument
and a point to my this will do the job
for me I guess.

Thanks for your help !
Get the points and the A :))
Enjoy
Yes , it will work
Only thing here is that  this solution will restrict the callback function to a  function taking no parameters,so you will not be able to use a function with one or more parameters as a timer callback.

Ufolk123,
I am interested in your solution to the problem as I can't use a timer that runs in its own thread. Can you send a brief outline of what you have mentioned.
Thanks in advance,
Ananthag