Timing problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andreas

    #1

    Timing problem

    Hi!

    I was using a standard windows timer, but it gave an error over 9% on
    a win 98 machine with no other programs running!

    Bacause of this, I decided to implement windows MultiMedia timer, and
    used code examples from msdn and this group. Everything works fine
    when I run it from VB, but if I complie and run, I get an error (and
    program termination) at the first timer event. (The .exe is ofcause
    runned from the same machine as VB.)

    I get the error message that '[some memory addresses] memory could not
    be "read".'

    My code is very, very short. Only the very nessecary rows are left and
    still the error occures. (I'm quite new to work with dll's outside
    VB.)

    This is my code:


    ========Module1 ======
    Option Explicit

    Public Declare Function timeSetEvent Lib "winmm.dll" _
    (ByVal uDelay As Long, _
    ByVal uResolution As Long, _
    ByVal lpTimeProc As Long, _
    ByVal dwUser As Long, _
    ByVal fuEvent As Long) As Long

    Public Declare Function timeKillEvent Lib "winmm.dll" _
    (ByVal uTimerID As Long) As Long

    Public Const TIME_PERIODIC = 1
    Public Const TIME_CALLBACK_F UNCTION = &H0

    Public Sub Main()
    Form1.Show
    End Sub

    Public Function TimerProc(ByVal uID As Long, _
    ByVal uMsg As Long, _
    ByVal dwUser As Long, _
    ByVal dw1 As Long, _
    ByVal dw2 As Long) As Long
    Form1.Print uID, uMsg, dwUser, dw1, dw2
    End Function

    ========Form1== ======
    Option Explicit
    Dim hTimerID

    Private Sub Form_Load()
    hTimerID = timeSetEvent(10 00, _
    10, _
    AddressOf Module1.TimerPr oc, _
    1, _
    TIME_PERIODIC Or TIME_CALLBACK_F UNCTION)
    End Sub

    Private Sub Form_Unload(Can cel As Integer)
    If hTimerID <> 0 Then
    timeKillEvent hTimerID
    hTimerID = 0
    End If
    End Sub

    best regards,
    Andreas Lundgren
Working...