cambalinho 125 Practically a Posting Shark

i did a class for the timer precision using the timeSetEvent(). of course i can have more than 7 instances from the Timer class(with 200ms or something so small). is these a limitation or what?

class Timer
{

private:
    static unsigned int TimerCount;
    UINT_PTR timerid;
    UINT m_uResolution=0;
    unsigned int TimerID=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);
        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()
    {
        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();
    }
};
unsigned int Timer::TimerCount=0;

after 7 instances(maybe less) the timerid give me NULL and the GetLastError() give me:
5 - access denied.
(on test i'm using it for gif animations)
is the timeSetEvent() limited or i'm using several resources?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.