/* CompletionEvent [in, optional] A handle to the event object to be signaled when the system has canceled the timer and all callback functions have completed. This parameter can be NULL. If this parameter is INVALID_HANDLE_VALUE, the function waits for any running timer callback functions to complete before returning. If this parameter is NULL, the function marks the timer for deletion and returns immediately. If the timer has already expired, the timer callback function will run to completion. However, there is no notification sent when the timer callback function has completed. Most callers should not use this option, and should wait for running timer callback functions to complete so they can perform any needed cleanup. So if you want to call the API in the timer callback function, please don't set the value of CompletionEvent to INVALID_HANDLE_VALUE. */
#define _WIN32_WINNT 0x0500 #include<windows.h> #include<stdio.h> /* Functions in your dll. */ HANDLE g_hTimer; VOID CALLBACK TimerCallback(PVOID lpParameter, BOOLEAN reserved) { /* Remember this callback is executed in a different thread, * so use synchronization if needed. */ DeleteTimerQueueTimer(NULL, g_hTimer, NULL); printf("Timer called\n"); } voidStart(void) { PVOID param = NULL; /* You can use this to pass a value to the callback. */ DWORD interval = 100; /* Interval in milliseconds. */ CreateTimerQueueTimer(&g_hTimer, NULL, TimerCallback, param, interval, interval, 0); } voidEnd(void) { DeleteTimerQueueTimer(NULL, g_hTimer, INVALID_HANDLE_VALUE); } /* Calling function. */ intmain(void) { Start(); getchar(); End(); getchar(); return0; }