i continue with problems for use a callback function in a class member :(
class Timer
{
private:
typedef std::function<void(void)> timerprocedure;
timerprocedure tmrprocedure;//can't be static
int MilliSecondsTimer;
bool blnDestroyed;
UINT TimerId;
HANDLE Timer1;
static void CALLBACK MyTimerProc( HWND hwnd, UINT message, UINT idTimer, DWORD dwTime)
{
tmrprocedure();//call the lambda timer function
//error: "invalid use of member 'Timer::tmrprocedure' in static member function"
}
public:
int SetMilliSeconds(int MilliSeconds)
{
MilliSecondsTimer = MilliSeconds;
return 0;
}
int GetMilliSeconds()
{
return (MilliSecondsTimer);
}
int Start(timerprocedure TimerProc)//receives the lambda timer function
{
tmrprocedure=TimerProc;
TimerId = SetTimer(0, 0, MilliSecondsTimer,MyTimerProc);//activate the timer with timer callback procedure
if(TimerId==NULL)
MessageBox(NULL,"error","error",MB_OK);
return 0;
}
int Stop()
{
KillTimer( 0,TimerId);
return 0;
}
~Timer()
{
Stop();
}
};
the tmrprocedure needs to be static, but i don't want it static... so how can i pass the this class pointer with SetTimer() and how can i get the pointer in MyTimerProc() callback?