Class-member-function as TimerProc


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

class SomeClass
   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
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 !
Who is Participating?
ufolk123Connect With a Mentor Commented:
Hi rhoepperger,

A class member can not be used as an argument to ordinary callbacks etc because all class member functions( other than static ) assume one extra parameter( this ) to be passed hence can not be used for funcitons with normal signatures.
You can do the following.
Create a ordinary wrapper function f.
Now pass the object pointer op as a paramter to f.
Call the function inside the f as a normal class function using
op->actual function

Use the f as argument to timer callbacks.
Get back in case of any doubts,.

rhoeppergerAuthor Commented:
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 :))
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.

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,
All Courses

From novice to tech pro — start learning today.