Running or running? Good question! Because the EXE file windows does not allow remote injection (or I don't know how to do it ...... ^ @ ^), But it is cumbersome to use ttimer in DLL, and it is not convenient to output ttimer in class mode (of course, it is also possible to use ttimer without class. Is there a simpler and more feasible way to meet my requirements? Therefore, timesetevent appears.
This is the prototype declaration of timesetevent. This function is included in the mmsystem unit:
Mmresult timesetevent (<br/> uint udelay, <br/> uint uresolution, <br/> lptimecallback lptimeproc, <br/> DWORD dwuser, <br/> uint fuevent <br/>); <br/>
Parameter description:
Udelay:Event latency, in milliseconds. If the value exceeds the maximum and minimum latency range supported by the timer, the program returns an error.
Uresolution:The timer event resolution, in milliseconds. Resolution increases as the value decreases. If it is set to zero, periodic events occur with maximum precision. In order to reduce the system overhead, the application should select the maximum value that can meet the requirements.
Lptimeproc:The address of the callback function. When a single event expires or a periodic event reaches a cycle. If the time_callback_set or time_callback_event_pulse flag is specified for fuevent, lptimeproc is treated as a pointer to an event object. The event will be set or pulsed upon completion of a single enent or periodically upon completion of periodic.
Dwuser:User-provided callback data.
Fuevent:Timer type. The parameter may contain one of the following values.
Value Meaning
Time_oneshot ---- one shot time occurs, once it passes through udelay Millisecond Time.
Time_periodic ---- Every udelay millisecond event occurs
It may also be the following value:
Value Meaning
Time_callback_function
The call back function calls the function specified by the lptimeproc parameter when the timer expires. The default value is used.
Time_callback_event_set
Call back event set when the timer expires, the window calls the setevent function and uses the lptimeproc parameter to set the event direction (to set the event pointed to by the lptimeproc parameter). The dwuser parameter is ignored.
Time_callback_event_pulse
Callback event pulse
Return Value:If the call is successful or other errors, an identifier is returned for the timer event. If the call fails or the timer event is created and the return value is zero, the value is also sent to the callback function.
Note:When you call the timesetevent function for periodic events, you must call the timekillevent function accordingly.
Call method:
Example:
Settimer (hwnd, // handle to Main Window <br/> idt_timer1, // timer identifier <br/> 10000, // 10-second interval <br/> (timerproc) null); // No timer callback </P> <p> <settimer (hwnd, // handle to Main Window <br/> idt_timer2, // timer identifier <br/> 300000, // five-minute interval <br/> (timerproc) null); // No timer callback <br/>
For example:
Running Effect of the instance:
Code unit:
Unit testunt; <br/> interface <br/> uses <br/> Windows, messages, sysutils, variants, classes, graphics, controls, forms, <br/> dialogs, stdctrls, mmsystem; // reference the mmsystem Unit <br/> type <br/> ttestfrm = Class (tform) <br/> btn_start: tbutton; <br/> btn_stop: tbutton; <br/> lbl_hint: tlabel; <br/> lbl_count: tlabel; <br/> procedure btn_startclick (Sender: tobject); <br/> procedure btn_stopclick (Sender: tobject ); <br/> private <br/> {private Declarations} <br/> Public <br/> {public declarations} <br/> end; <br/> var <br/> testfrm: ttestfrm; <br/> Implementation <br/> {$ R *. DFM} <br/> var <br/> timeid: Cardinal; <br/> icount: integer = 0; <br/> procedure mycallback (utimerid, umessage: uint; dwuser, dw1, dw2: DWORD) stdcall; // The callback process. The timesetevent function is referenced in mmsystem, the procedure is defined as follows <br/> begin <br/> // The number is incremented per second, and the visual control (such as the caption of the form, because it also notifies Windows taskbar and so on) <br/> // There is a synchronization problem between them. It is best to use the changes in log storage <br/> // testfrm. caption: = inttostr (icount); <br/> testfrm. lbl_count.caption: = inttostr (icount); <br/> // savelog (icount); // a self-defined log Stored Procedure <br/> Inc (icount ); <br/> end; <br/> procedure ttestfrm. btn_startclick (Sender: tobject); // press start to start counting <br/> begin <br/> timeid: = timesetevent (, @ mycallback, 0, time_periodic ); // 1000 ms latency, loop mode, return counter handle <br/> end; <br/> procedure ttestfrm. btn_stopclick (Sender: tobject); <br/> begin <br/> timekillevent (timeid); // destroy the timer thread and stop counting <br/> icount: = 0; <br/> end; <br/> end. <br/>
So how can we apply it to DLL?
To be continued ......