Quantcast
Channel: CodeGuru Forums - C++ and WinAPI
Viewing all articles
Browse latest Browse all 583

how use CreateTimerQueueTimer()?

$
0
0
why i can't use, correctly, the CreateTimerQueueTimer()?
see these code:
Code:

class Timer
{

private:
    static unsigned int TimerCount;
    static vector<HANDLE> m_timerHandle;
    UINT_PTR timerid;
    UINT m_uResolution=0;
    unsigned int TimerID=0;
    DWORD intInterval=0;

    static void CALLBACK TimerProc(PVOID InstancePointer, BOOLEAN TimerOrWaitFired)
    {
        Timer* obj=(Timer*)(InstancePointer);
        if(obj->timerprocedure!=nullptr)
            obj->timerprocedure();
    }

public:

    std::function<void()> timerprocedure=EmptyEvent;
    Timer(std::function<void()> tmrprocedure=EmptyEvent)
    {
        TimerCount+=1;
        TimerID=TimerCount-1;
        timerprocedure=tmrprocedure;
        m_timerHandle.resize(500);
    }

    void Stop()
    {
        if( m_timerHandle[TimerID]!=0)
        {
            if(DeleteTimerQueueTimer(NULL,  m_timerHandle[TimerID], INVALID_HANDLE_VALUE)==FALSE)
                DebugText("close timer error: " + to_string(TimerCount) + "  " + to_string(GetLastError()));
        }
    }

    DWORD GetInterval()
    {
        return intInterval;
    }

    void SetInterval(DWORD uintInterval)
    {
        intInterval = uintInterval;
    }

    property <DWORD> Interval{GetProperty(Timer::GetInterval),SetProperty(Timer::SetInterval)};

    void Start()
    {
        if(  m_timerHandle[TimerID]!=0)
            Stop();
        if (CreateTimerQueueTimer(&m_timerHandle[TimerID],NULL, &Timer::TimerProc,this, 0,intInterval,WT_EXECUTEDEFAULT)==0)
            DebugText("error\t" + to_string(GetLastError()));
    }

    ~Timer()
    {
        if(  m_timerHandle[TimerID]!=0)
            Stop();
    }
};
unsigned int Timer::TimerCount=0;
vector<HANDLE> Timer::m_timerHandle={0};

i get several problems, even with multithread code. but just seen these class: what i'm doing wrong?
unless i'm using the flags incorrectly :(

Viewing all articles
Browse latest Browse all 583

Trending Articles