timeSetEvent

  UINT timeSetEvent(wDelay, wResolution, lpFunction, dwUser, wFlags)    
  UINT wDelay;    
  UINT wResolution;    
  LPTIMECALLBACK lpFunction;    
  DWORD dwUser;    
  UINT wFlags;    

The timeSetEvent 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

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.

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.

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.

dwUser

Contains user-supplied callback data.

wFlags

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

Value Meaning

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 Function

void CALLBACK TimeFunc(wID, wMsg, dwUser, dw1, dw2)
UINT wID;
UINT wMsg;
DWORD dwUser;
DWORD dw1;
DWORD 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

wID

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

wMsg

Not used.

dwUser

User instance data supplied to the dwUser parameter of timeSetEvent.

dw1

Not used.

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