Steady Timer Messages in a Dynamic-Link Library (DLL)Last reviewed: April 6, 1995Article ID: Q74412 |
The information in this article applies to:
SUMMARYIn the Microsoft Windows graphical environment, a dynamic-link library (DLL) can receive steady timer messages, even as various applications that link into the DLL are started and terminated. However, it cannot do so by calling the SetTimer() API directly as an application typically does. To receive steady timer messages, a DLL can launch a hidden application and use that application's message queue to receive the timer messages.
MORE INFORMATIONThe SetTimer() API is used to create a Windows timer. When the timer expires, Windows needs a message queue into which it can place a WM_TIMER message. A message queue is required even if a timer notification function is specified as the lpTimerFunc parameter to SetTimer(). Because a DLL is not a task, it does not have a message queue. When a DLL calls SetTimer(), Windows places the resulting WM_TIMER messages into the message queue of the currently active task, which is the application instance that called into the DLL. If this application instance should terminate, its message queue is destroyed, and the DLL does not receive any more timer messages. If the DLL specified a timer notification function, the notification function is not called again. For a DLL to receive a steady flow of timer messages, the timer messages must go into a message queue that will remain present while the various applications that link into the DLL are started and terminated. One way to achieve this is to launch a hidden application from the DLL. The DLL can use that application's message queue to receive steady timer messages. This technique could be implemented as follows:
Timers are a scarce system resource. If the SetTimer() call fails, no timers are available for use. Before the DLL terminates, it should free the timer. It can do so by calling KillTimer(). It then sends a WM_CLOSE message to the MYTIMER application, which terminates MYTIMER.
|
Additional reference words: 3.00 3.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |