Windows timer callback functions
Posted on 1998-09-01
I wnat to setup several timers (one for each instance of an object that I will dynamically create) and have a member function of that object be used as the callback function. However when I try to to this I get a compiler error as follows:
error C2664: 'SetTimer' : cannot convert parameter 3 from 'void (struct HWND__ *, unsigned int, unsigned int, unsigned long)' to 'void (__stdcall *)(struct HWND__ *, unsigned int, unsigned int, unsigned long)'
The Win32 documentation says to declare the callback function like this :
VOID CALLBACK TimerProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime );
which I have done to no avail.
My question is how can I use a member function as a timer callback?
Some Of my code:
SetTimer(ID_TIMER_1, 5000, this->TimerTimeout);
void CMyClass::TimerTimeout(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
if (TRUE == DoStateMachine(m_currentState))
// Declarations and stuff here
void CALLBACK TimerTimeout( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);