我现在对一个硬件设备进行编程。在编程过程中,我们要使用一个定时器来刷新(获取)硬件的状态。然后根据各种不同状态,来进行不同的操作。现在,我要把这个功能进行封装,就是我要编写一个DLL来封装这些功能,以便以后扩展使用。DLL中定义个事件来触发各种硬件状态。但是我知道用VB写DLL无法调用定时器(或者我还不知道如何调用)来获取硬件状态。请问我现在该如何解决这个问题。
调试欢乐多
byval hwnd as long, 'handle of window for timer messages
byval uMsg as long, 'WM_TIMER message
byval idEvent as long, 'timer identifier
byval dwTime as long 'current system time
)end subSetTimer 0, 0, 1000, AddressOf lpTimerFunc
Dim blnCancel As Boolean
Sub TimerEvent(ByVal Interval As Long)'最小周期1s
Do
DoEvents
If blnCancel Then Exit Do
Delay Interval
Call aaa
Loop
End Sub
Sub Delay(ByVal t As Long)
Dim start As Long
start = Timer
Do
DoEvents If Timer >= start + t Then Exit Do
Loop
End Sub
Sub aaa()
Static num As Integer
num = num + 1
Me.Caption = num
End SubPrivate Sub Form_Load()
Me.Show
DoEvents
TimerEvent (1)
End SubPrivate Sub Form_Unload(Cancel As Integer)
blnCancel = True
End
End Sub
2)你可以使用多媒体定时器来实现定时任务,即使没有窗体,参考
http://www.csdn.com.cn/program/580.htm
3)也可以在DLL里面开启一个线程循环来完成你说的任务(可用API函数Sleep控制延时)以上仅供参考
ti.Interval = 100
ti.Enabled = TrueEnd SubPrivate Sub ti_Timer()'这里写入你想要的函数
End Sub
这样也不知道可不可以,似乎这个很简单
ti.Interval = 100
ti.Enabled = True End Sub出现了错误