timeSetEvent

Syntax

WORD timeSetEvent(wDelay, wResolution, lpFunction, dwUser, wFlags)

This function sets up a timed callback event. The event can be a one-time event or a periodic event. Once activated, the event calls the specified callback function.

Parameters

WORD wDelay

Specifies the event period in milliseconds. If the delay is less than the minimum period supported by the timer, or greater than the maximum period supported by the timer, the function returns an error.

WORD wResolution

Specifies the accuracy of the delay in milliseconds. The resolution of the timer event increases with smaller wResolution values. To reduce system overhead, use the maximum wResolution value appropriate for your application.

LPTIMECALLBACK lpFunction

Specifies the procedure address of a callback function that is called once upon expiration of a one-shot event or periodically upon expiration of periodic events.

DWORD dwUser

Contains user-supplied callback data.

WORD wFlags

Specifies the type of timer event, using one of the following flags:

TIME_ONESHOT

Event occurs once, after wPeriod milliseconds.

TIME_PERIODIC

Event occurs every wPeriod milliseconds.

Return Value

Returns an ID code that identifies the timer event. Returns NULL if the timer event was not created. The ID code is also passed to the callback function.

Comments

Using this function to generate a high-frequency periodic-delay event (with a period less than 10 milliseconds) can consume a significant portion of the system CPU bandwidth. Any call to timeSetEvent for a periodic-delay timer must be paired with a call to timeKillEvent.

The callback function must reside in a DLL. You don't have to use MakeProcInstance to get a procedure-instance address for the callback function.

Callback

void FAR PASCAL TimeFunc(wID, wMsg, dwUser, dw1, dw2)

TimeFunc is a placeholder for the application-supplied function name. The actual name must be exported by including it in the EXPORTS statement of the module-definition file for the DLL.

Parameters

WORD wID

The ID of the timer event. This is the ID returned by timeSetEvent.

WORD wMsg

Not used.

DWORD dwUser

User instance data supplied to the dwUser parameter of timeSetEvent.

DWORD dw1

Not used.

DWORD dw2

Not used.

Comments

Because the callback is accessed at interrupt time, it must reside in a DLL, and its code segment must be specified as FIXED in the module-definition file for the DLL. Any data that the callback accesses must be in a FIXED data segment as well. The callback may not make any system calls except for PostMessage, timeGetSystemTime, timeGetTime, timeSetEvent, timeKillEvent, midiOutShortMsg, midiOutLongMsg, and OutputDebugStr.

See Also

timeKillEvent, timeBeginPeriod, timeEndPeriod