各位请帮帮我
程序在VB里是正常的编译完成就不正常,是内存不能为“written"的错误
在timeSetEvent的回调函数下不能调用其他函数和过程,但可以执行一些代码,一旦调用编译后就出错
代码如下
模块:
Option ExplicitType LARGE_INTEGER
    lowpart As Long
    highpart As Long
End TypePublic Declare Function QueryPerformanceCounter Lib "kernel32" _
        (lpPerformanceCount As LARGE_INTEGER) As Long
Public Declare Function QueryPerformanceFrequency Lib "kernel32" _
        (lpFrequency As LARGE_INTEGER) As Long
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal _
        uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, _
        ByVal uFlags As Long) As Long
Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
Public Declare Function GetTickCount Lib "kernel32" () As LongPublic lMSFreq As Long
Public TimerCount As Single
Public lmmCount As Single
Public lTimeID As Long
Public actTime1 As Long
Public actTime2 As Long
Public iCountStart As SingleDim iCount As Single'timeSetEvent的回调函数
Sub TimeProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, _
    ByVal dw1 As Long, ByVal dw2 As Long)
    
    Form1.Text2.Text = Format$(lmmCount, "00.00")
    lmmCount = lmmCount - 0.01
    If lmmCount <= 58 Then
        iCountStart = 60
        lmmCount = 60
        TimerCount = 60
        EndCount
    End If
End Sub
Sub EndCount()
    iCount = iCountStart
    iCountStart = 0
    timeKillEvent lTimeID
    actTime2 = GetTickCount - actTime1
    With Form1
        .Command1.Enabled = True
        .Command2.Enabled = False
        .Timer1.Enabled = False
        
        .Text1 = "计数器记时" + Format$((60 - iCount), "00.00") + "  " _
                + "实际经过时间" + Format$((actTime2 / 1000), "00.00")
                
        .Text2 = "计数器记时" + Format$((60 - lmmCount), "00.00") + "  " _
                + "实际经过时间" + Format$((actTime2 / 1000), "00.00")
                
        .Text3 = "计数器记时" + Format$((60 - TimerCount), "00.00") + "  " _
                + "实际经过时间" + Format$((actTime2 / 1000), "00.00")
    End With
End Sub
窗口:Option ExplicitPrivate Sub Command1_Click()
    Dim lagTick1 As LARGE_INTEGER
    Dim lagTick2 As LARGE_INTEGER
    Dim lTen As Long
    
    Command2.Enabled = True
    Command1.Enabled = False
    
    iCountStart = 60
    lmmCount = 60
    TimerCount = 60
    
    actTime1 = GetTickCount
    lTimeID = timeSetEvent(10, 0, AddressOf TimeProc, 1, 1)
    Timer1.Enabled = True
    
    lTen = 10 * lMSFreq
    Call QueryPerformanceCounter(lagTick1)
    lagTick2 = lagTick1
    
    While iCountStart > 0
        Call QueryPerformanceCounter(lagTick2)
        '如果时钟震动次数超过10毫秒的次数则刷新Text1的显示
        If lagTick2.lowpart - lagTick1.lowpart > lTen Then
            lagTick1 = lagTick2
            iCountStart = iCountStart - 0.01
            Text1.Text = Format$(iCountStart, "00.00")
        End If
        DoEvents
    Wend
End SubPrivate Sub Command2_Click()
    EndCount
End SubPrivate Sub Command3_Click()
Command2_Click
Unload Me
End
End SubPrivate Sub Form_Load()
    Dim lim As LARGE_INTEGER
    
    Text1.Text = "60.00"
    Text2.Text = "60.00"
    Text3.Text = "60.00"
    Command1.Caption = "开始倒记时"
    Command2.Caption = "停止记时"
    Command2.Enabled = False
    
    '获得系统板上时钟频率
    QueryPerformanceFrequency lim
    
    '将频率除以1000就的出时钟1毫秒震动的次数
    lMSFreq = (lim.highpart * 2 ^ 16) \ 1000 + lim.lowpart \ 1000
    Timer1.Interval = 10
    Timer1.Enabled = False
End SubPrivate Sub Timer1_Timer()
    TimerCount = TimerCount - 0.01
    Text3.Text = Format$(TimerCount, "00.00")
    If TimerCount <= 0 Then
        Timer1.Enabled = False
    End If
End Sub是多媒体高精度计时器
望不吝赐教,谢谢