heres my timer class:
or it's the 'this' or i don't know.
after 6 or 7 Timer class instances the timeSetEvent() give me NULL and GetLastError():
- 6: acess denied;
i don't have sure about the error. but maybe it's the instance pointer. can anyone explain better to me?
Code:
#define min(x, y) __min((x), (y))
#define max(x,y) __max((x), (y))
class Timer
{
private:
UINT_PTR timerid=0;
UINT m_uResolution=0;
unsigned int intInterval=0;
static void CALLBACK _TimerProc(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
Timer* obj=reinterpret_cast<Timer*>(dwUser);
obj->timerprocedure();
}
public:
std::function<void()> timerprocedure=NULL;
Timer(std::function<void()> tmrprocedure=NULL)
{
timerprocedure=tmrprocedure;
}
void Stop()
{
if(timerid!=0)
{
timeKillEvent(timerid);
timeEndPeriod (m_uResolution);
}
}
unsigned int GetInterval()
{
return intInterval;
}
void SetInterval(unsigned int uintInterval)
{
intInterval = uintInterval;
}
property <unsigned int> Interval{GetProperty(Timer::GetInterval),SetProperty(Timer::SetInterval)};
void Start()
{
Stop();
TIMECAPS tc;
timeGetDevCaps(&tc, sizeof(TIMECAPS));
m_uResolution = min(max(tc.wPeriodMin, 0), tc.wPeriodMax);
timeBeginPeriod(m_uResolution);
timerid = timeSetEvent(intInterval, m_uResolution, &Timer::_TimerProc, reinterpret_cast<DWORD>(this),TIME_PERIODIC);
if (timerid==0)
DebugText("error\t" + to_string(GetLastError()));
}
~Timer()
{
Stop();
}
};
after 6 or 7 Timer class instances the timeSetEvent() give me NULL and GetLastError():
- 6: acess denied;
i don't have sure about the error. but maybe it's the instance pointer. can anyone explain better to me?