May 5, 2016 at 5:30pm UTC
i'm trying change my Timer class for see if works better:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
class Timer
{
private :
static unsigned int TimerCount;
PHANDLE m_timerHandle=NULL;
UINT_PTR timerid;
UINT m_uResolution=0;
unsigned int TimerID=0;
unsigned int intInterval=0;
static void CALLBACK TimerProc(void * InstancePointer, BOOLEAN TimerOrWaitFired)
{
Timer* obj=reinterpret_cast <Timer*>(InstancePointer);
if (obj->timerprocedure!=nullptr )
obj->timerprocedure();
}
public :
std::function<void ()> timerprocedure=EmptyEvent;
Timer(std::function<void ()> tmrprocedure=EmptyEvent)
{
TimerCount++;
TimerID=TimerCount-1;
timerprocedure=tmrprocedure;
}
void Stop()
{
DeleteTimerQueueTimer(NULL, m_timerHandle, NULL);
CloseHandle (m_timerHandle);
}
unsigned int GetInterval()
{
return intInterval;
}
void SetInterval(unsigned int uintInterval)
{
intInterval = uintInterval;
}
property <unsigned int > Interval{GetProperty(Timer::GetInterval),SetProperty(Timer::SetInterval)};
void Start()
{
if (m_timerHandle!=0)
Stop();
if (CreateTimerQueueTimer(m_timerHandle,NULL,TimerProc,reinterpret_cast <PVOID>(this ),0,(DWORD)intInterval ,WT_EXECUTEINTIMERTHREAD)==0)
DebugText("error\t" + to_string(GetLastError()));
}
~Timer()
{
if (m_timerHandle!=0)
Stop();
}
};
unsigned int Timer::TimerCount=0;
compiles and i don't get any error. but i think it's a memory leak.
can anyone tell me where i mistake on CreateTimerQueueTimer()?
"Process terminated with status -1073741819 (0 minute(s), 2 second(s))"
Last edited on May 5, 2016 at 5:34pm UTC
May 10, 2016 at 12:09pm UTC
Change line 15:
if (obj->timerprocedure!=nullptr ) // Note: do not compare with nullptr
Also note that these type of timer are done with parallel threads. But most gui functions are not thread safe.
May 10, 2016 at 11:40pm UTC
theres another problem, i was using more than 16 timers. but we can't.
thanks for all
May 11, 2016 at 10:14am UTC
i'm sorry, but is just change the const?
i'm sorry, but these isn't a flag, so i don't know use it :(