반응형

http://msdn.microsoft.com/ko-kr/library/windows/desktop/ms682483(v=vs.85).aspx








Creates a queue for timers. Timer-queue timers are lightweight objects that enable you to specify a callback function to be called at a specified time.



Syntax

HANDLE WINAPI CreateTimerQueue(void);

Parameters

This function has no parameters.

Return value

If the function succeeds, the return value is a handle to the timer queue. This handle can be used only in functions that require a handle to a timer queue.

If the function fails, the return value is NULL. To get extended error information, callGetLastError.






Remarks

To add a timer to the queue, call the CreateTimerQueueTimer function. To remove a timer from the queue, call the DeleteTimerQueueTimer function.

When you are finished with the queue of timers, call the DeleteTimerQueueEx function to delete the timer queue. Any pending timers in the queue are canceled and deleted.

To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later. For more information, see Using the Windows Headers.



BLOG main image

0x0500 은 윈도우 2000 을 말한다, XP 보다도 낮은버전

Windows XP =_WIN32_WINNT>=0x0501

WINVER>=0x0501

Windows 2000 =_WIN32_WINNT>=0x0500

WINVER>=0x0500



 









An application-defined function that serves as the starting address for a timer callback or a registered wait callback. Specify this address when calling theCreateTimerQueueTimerRegisterWaitForSingleObject function.

The WAITORTIMERCALLBACK type defines a pointer to this callback function.WaitOrTimerCallback is a placeholder for the application-defined function name.

Syntax

VOID CALLBACK WaitOrTimerCallback(
  _In_  PVOID lpParameter,
  _In_  BOOLEAN TimerOrWaitFired
);

Parameters

lpParameter [in]

The thread data passed to the function using a parameter of theCreateTimerQueueTimer or RegisterWaitForSingleObject function.

TimerOrWaitFired [in]

If this parameter is TRUE, the wait timed out. If this parameter is FALSE, the wait event has been signaled. (This parameter is always TRUE for timer callbacks.)

Return value

This function does not return a value.

Remarks

This callback function must not call the TerminateThread function.

For an example that uses this callback function, see Using Timer Queues.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

WinBase.h on Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2 (include Windows.h);
Winnt.h on Windows 8 and Windows Server 2012



 







예제


#include <windows.h>
#include <stdio.h>

HANDLE gDoneEvent;

VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired)
{
    if (lpParam == NULL)
    {
        printf("TimerRoutine lpParam is NULL\n");
    }
    else
    {
        // lpParam points to the argument; in this case it is an int

        printf("Timer routine called. Parameter is %d.\n", 
                *(int*)lpParam);
        if(TimerOrWaitFired)
        {
            printf("The wait timed out.\n");
        }
        else
        {
            printf("The wait event was signaled.\n");
        }
    }

    SetEvent(gDoneEvent);
}

int main()
{
    HANDLE hTimer = NULL;
    HANDLE hTimerQueue = NULL;
    int arg = 123;

    // Use an event object to track the TimerRoutine execution
    gDoneEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (NULL == gDoneEvent)
    {
        printf("CreateEvent failed (%d)\n", GetLastError());
        return 1;
    }

    // Create the timer queue.
    hTimerQueue = CreateTimerQueue();
    if (NULL == hTimerQueue)
    {
        printf("CreateTimerQueue failed (%d)\n", GetLastError());
        return 2;
    }

    // Set a timer to call the timer routine in 10 seconds.
    if (!CreateTimerQueueTimer( &hTimer, hTimerQueue, 
            (WAITORTIMERCALLBACK)TimerRoutine, &arg , 10000, 0, 0))
    {
        printf("CreateTimerQueueTimer failed (%d)\n", GetLastError());
        return 3;
    }

    // TODO: Do other useful work here 

    printf("Call timer routine in 10 seconds...\n");

    // Wait for the timer-queue thread to complete using an event 
    // object. The thread will signal the event at that time.

    if (WaitForSingleObject(gDoneEvent, INFINITE) != WAIT_OBJECT_0)
        printf("WaitForSingleObject failed (%d)\n", GetLastError());

    CloseHandle(gDoneEvent);

    // Delete all timers in the timer queue.
    if (!DeleteTimerQueue(hTimerQueue))
        printf("DeleteTimerQueue failed (%d)\n", GetLastError());

    return 0;
}




 


반응형

+ Recent posts