Timing problem - basic.visual

This is a discussion on Timing problem - basic.visual ; 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 ...

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Timing problem

  1. Default 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.)

    Do you see any direct errors in 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_FUNCTION = &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(1000, _
    10, _
    AddressOf Module1.TimerProc, _
    1, _
    TIME_PERIODIC Or TIME_CALLBACK_FUNCTION)
    End Sub

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

    best regards,
    Andreas Lundgren

  2. Default Re: Timing problem


    "Andreas" <d99alu@efd.lth.se> wrote in message
    news:f7cd4365.0310270108.5c532d88@posting.google.com...
    > 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.)
    >
    > Do you see any direct errors in 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_FUNCTION = &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(1000, _
    > 10, _
    > AddressOf Module1.TimerProc, _
    > 1, _
    > TIME_PERIODIC Or TIME_CALLBACK_FUNCTION)
    > End Sub
    >
    > Private Sub Form_Unload(Cancel As Integer)
    > If hTimerID <> 0 Then
    > timeKillEvent hTimerID
    > hTimerID = 0
    > End If
    > End Sub
    >
    > best regards,
    > Andreas Lundgren


    I think I may have been one of the people posting about the media timer. I
    copied your code, and got the same result: fine in VB, exception in the
    executable. I went back to an older example, with the same result (I had never
    actually built that example). If it is any consolation, it is not you.

    The prime suspect has to be the call back function (TimerProc). I can't find
    anything to indicate what is wrong with it, but it is surely the problem. Maybe
    one or more of the variables should be ByRef instead of ByVal. Or be an Integer
    instead of a Long. Or the Return type is wrong. Maybe there is a sixth parameter
    now.

    I do know that everything has to be exactly right for a callback. I guess when
    it runs in VB, VB smoothes out the wrinkles (which is not very helpful).

    Hope somebody can identify what is up here.
    Steve




  3. Default Re: Timing problem

    Hi!

    Thanks a lot for putting so much effort in this group Mr. Gerrard,
    it's really appreciated!

    My biggest problem is that i cand find a complement in the types given
    at msdn. This must be declared somewhere?!?

    Where can you find all the different type declarations that is used
    for windows on msdn, or what file can you include so that you can use
    this types?

    I read on msdn that for instance UINT is of different size on
    different platforms. "UINT = Portable unsigned integer type whose size
    is determined by host environment (32 bits for Windows NT and Windows
    95). Synonym for unsigned int. Used in place of WORD except in the
    rare cases where a 16-bit unsigned quantity is desired even on 32-bit
    platforms."

    How do you solve this?

    This is the timeSetEvent struct:
    MMRESULT timeSetEvent(
    UINT uDelay,
    UINT uResolution,
    LPTIMECALLBACK lpTimeProc,
    DWORD_PTR dwUser,
    UINT fuEvent
    );
    and this is the callback function:
    void (CALLBACK)(
    UINT uTimerID,
    UINT uMsg,
    DWORD_PTR dwUser,
    DWORD_PTR dw1,
    DWORD_PTR dw2
    );


    > I think I may have been one of the people posting about the media timer. I
    > copied your code, and got the same result: fine in VB, exception in the
    > executable. I went back to an older example, with the same result (I had never
    > actually built that example). If it is any consolation, it is not you.
    >
    > The prime suspect has to be the call back function (TimerProc). I can't find
    > anything to indicate what is wrong with it, but it is surely the problem. Maybe
    > one or more of the variables should be ByRef instead of ByVal. Or be an Integer
    > instead of a Long. Or the Return type is wrong. Maybe there is a sixth parameter
    > now.
    >
    > I do know that everything has to be exactly right for a callback. I guess when
    > it runs in VB, VB smoothes out the wrinkles (which is not very helpful).
    >
    > Hope somebody can identify what is up here.
    > Steve


    "Steve Gerrard" <notstevegerrard@comcast.net> wrote in message news:<2ZCdnfl_EbcsdwCiRVn-tg@comcast.com>...
    > "Andreas" <d99alu@efd.lth.se> wrote in message
    > news:f7cd4365.0310270108.5c532d88@posting.google.com...
    > > 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.)
    > >
    > > Do you see any direct errors in 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_FUNCTION = &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(1000, _
    > > 10, _
    > > AddressOf Module1.TimerProc, _
    > > 1, _
    > > TIME_PERIODIC Or TIME_CALLBACK_FUNCTION)
    > > End Sub
    > >
    > > Private Sub Form_Unload(Cancel As Integer)
    > > If hTimerID <> 0 Then
    > > timeKillEvent hTimerID
    > > hTimerID = 0
    > > End If
    > > End Sub
    > >
    > > best regards,
    > > Andreas Lundgren


  4. Default Re: Timing problem

    On Mon, 27 Oct 2003 20:04:18 -0800, "Steve Gerrard"
    <notstevegerrard@comcast.net> wrote:

    >
    >"Andreas" <d99alu@efd.lth.se> wrote in message
    >news:f7cd4365.0310270108.5c532d88@posting.google.com...
    >> 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.)
    >>
    >> Do you see any direct errors in 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_FUNCTION = &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(1000, _
    >> 10, _
    >> AddressOf Module1.TimerProc, _
    >> 1, _
    >> TIME_PERIODIC Or TIME_CALLBACK_FUNCTION)
    >> End Sub
    >>
    >> Private Sub Form_Unload(Cancel As Integer)
    >> If hTimerID <> 0 Then
    >> timeKillEvent hTimerID
    >> hTimerID = 0
    >> End If
    >> End Sub
    >>
    >> best regards,
    >> Andreas Lundgren

    >

    I have played around with your code and this is what I came up with...
    I believe Two things are happening in your code...
    1) Using the Form_Load Event will choke on it..
    Starting and stopping the Timer should be handled under a fully realized
    form...

    2) Printing to the form doesn't work when compiled for some reason or other...

    Maybe thinking along these lines you'll be able to find a work around for your
    project...


    '********* Module Code ************
    Option Explicit

    Public lNumEvents As Long

    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_FUNCTION = &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

    ' Compiled Code seems to Barf on the next line....
    ' Form1.Print uID, uMsg, dwUser, dw1, dw2

    'This works for me...
    lNumEvents = lNumEvents + 1

    End Function

    '********* Form Code ******************

    Option Explicit
    'Original was a Variant...
    Dim hTimerID As Long 'Make sure this is a Long

    'I added a command button and rearranged the code

    Private Sub Command1_Click()
    Static bLp As Boolean
    If Not bLp Then
    bLp = True
    lNumEvents = 0
    hTimerID = timeSetEvent(1000, _
    10, _
    AddressOf Module1.TimerProc, _
    1, _
    TIME_PERIODIC Or TIME_CALLBACK_FUNCTION)

    Else
    bLp = False
    timeKillEvent hTimerID
    hTimerID = 0
    MsgBox "Number of events = " & CStr(lNumEvents)
    End If

    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    'Leave the following in case we click the 'X'
    If hTimerID <> 0 Then
    timeKillEvent hTimerID
    hTimerID = 0
    End If
    End Sub


    Have a good day...

    Don

  5. Default Re: Timing problem

    "Andreas" <d99alu@efd.lth.se> wrote in message
    news:f7cd4365.0310270108.5c532d88@posting.google.com...
    > 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.)
    >
    > Do you see any direct errors in my code?


    I believe the MM timer calls back from a different thread, which is very
    problematic in VB6 (less so in VB5). It can be done, but it's nontrivial.
    I have plans to release a library for doing "free threading" (I released a
    demo on my website in July), but haven't gotten around to it yet. I suggest
    you solve the problem in another way.

    If the error of 9% was problematic because it was cumulative (i.e. you're
    trying to count to a minute by counting 60 periods of one second), you may
    consider keeping track of the total time seperately (using the Timer
    function, perhaps).

    Another solution is to put a callback for the MM timer in, say, a C DLL
    which then calls SendMessage() to give a message to your form. If you don't
    have a C compiler, you might look at LCC-Win32, which is free and decent.
    Having this around would also help your problem of not knowing exactly what
    VB type equivilants are -- just look in LCC's headers.

    Or you could make your app a multithreaded COM app, and create a COM
    component that Sleep()s for a specific amount of time and then raises an
    event or something.

    None of this will be as "tight" as using the MM timer directly, but for now,
    I don't see a tremendous amount of options.


    Murphy
    www.ConstantThought.com



  6. Default Re: Timing problem


    <Don@home.com> wrote in message
    news:ea6tpvghud90dfg5f7v99ah32gbtmrkr30@4ax.com...
    > On Mon, 27 Oct 2003 20:04:18 -0800, "Steve Gerrard"
    > I have played around with your code and this is what I came up with...
    > I believe Two things are happening in your code...
    > 1) Using the Form_Load Event will choke on it..
    > Starting and stopping the Timer should be handled under a fully realized
    > form...
    >
    > 2) Printing to the form doesn't work when compiled for some reason or other...
    >
    > Maybe thinking along these lines you'll be able to find a work around for your
    > project...
    >
    >
    > '********* Module Code ************
    > Option Explicit
    >
    > Public lNumEvents As Long
    >
    > 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_FUNCTION = &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
    >
    > ' Compiled Code seems to Barf on the next line....
    > ' Form1.Print uID, uMsg, dwUser, dw1, dw2
    >
    > 'This works for me...
    > lNumEvents = lNumEvents + 1
    >
    > End Function
    >
    > '********* Form Code ******************
    >
    > Option Explicit
    > 'Original was a Variant...
    > Dim hTimerID As Long 'Make sure this is a Long
    >
    > 'I added a command button and rearranged the code
    >
    > Private Sub Command1_Click()
    > Static bLp As Boolean
    > If Not bLp Then
    > bLp = True
    > lNumEvents = 0
    > hTimerID = timeSetEvent(1000, _
    > 10, _
    > AddressOf Module1.TimerProc, _
    > 1, _
    > TIME_PERIODIC Or TIME_CALLBACK_FUNCTION)
    >
    > Else
    > bLp = False
    > timeKillEvent hTimerID
    > hTimerID = 0
    > MsgBox "Number of events = " & CStr(lNumEvents)
    > End If
    >
    > End Sub
    >
    > Private Sub Form_Unload(Cancel As Integer)
    > 'Leave the following in case we click the 'X'
    > If hTimerID <> 0 Then
    > timeKillEvent hTimerID
    > hTimerID = 0
    > End If
    > End Sub
    >
    >
    > Have a good day...
    >
    > Don


    I have built Don's example, and it worked for me as well.
    This establishes that the timer proc is okay, and the interface to winmm.dll in
    general is okay.

    I was a little suspicious of the form printing as well. In fact, as Murphy
    points out in his post, the separate threading of the MM timer is apparently
    fraught with peril in general. Don't do anything in the timer proc itself that
    involves the OS or VB stuff (like getting the time); just record the event in
    some way.

    I was able to add a text box and timer set at 50 ms, and this event handler, and
    got a stable exectuable that continuously updates the form:
    Private Sub Timer1_Timer()
    Text1.Text = Module1.lNumEvents
    End Sub



  7. Default Re: Timing problem

    "Murphy McCauley" <MurphyAt@AtConstantThoughtDot.DotCom> wrote in message news:<BBAnb.6582$Is.3050@newssvr27.news.prodigy.com>...
    > "Andreas" <d99alu@efd.lth.se> wrote in message
    > news:f7cd4365.0310270108.5c532d88@posting.google.com...
    > > 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.)
    > >
    > > Do you see any direct errors in my code?

    >
    > I believe the MM timer calls back from a different thread, which is very
    > problematic in VB6 (less so in VB5). It can be done, but it's nontrivial.
    > I have plans to release a library for doing "free threading" (I released a
    > demo on my website in July), but haven't gotten around to it yet. I suggest
    > you solve the problem in another way.
    >
    > If the error of 9% was problematic because it was cumulative (i.e. you're
    > trying to count to a minute by counting 60 periods of one second), you may
    > consider keeping track of the total time seperately (using the Timer
    > function, perhaps).
    >
    > Another solution is to put a callback for the MM timer in, say, a C DLL
    > which then calls SendMessage() to give a message to your form. If you don't
    > have a C compiler, you might look at LCC-Win32, which is free and decent.
    > Having this around would also help your problem of not knowing exactly what
    > VB type equivilants are -- just look in LCC's headers.
    >
    > Or you could make your app a multithreaded COM app, and create a COM
    > component that Sleep()s for a specific amount of time and then raises an
    > event or something.
    >
    > None of this will be as "tight" as using the MM timer directly, but for now,
    > I don't see a tremendous amount of options.
    > Murphy
    > www.ConstantThought.com


    Hi!

    Thanks for the help. My project is a project via our university for
    medical science. I don't make any money doing this, so your free help
    is very appreciated!

    My program gives a patient 4 seconds. to press a button. The button is
    connected to a PIC processor that sends a signal to the PC via the
    COM-port. My VB application get either an event from the COM-port or
    from the timer (every 500 ms) then this repeats until 30 min has
    passed by.

    Maybe I could have a timer event every 10 ms, and don't accumulate but
    check with timeGetTime or Timer. To read the Timer or timeGetTime +
    compare with a value can't take that long? Will there be enough time
    left to catch if button is pressed? This would give me a maximum error
    of 11 ms (10 ms + 9% error) both on the 4 seconds period and of the
    total 30 min.

    This, of cause, will give my a quit load of work... : /

    I'm going to try an other timer I found this (European) morning at
    http://www.vbaccelerator.com/codelib...r/hirestmr.htm or maybe
    change to win2k, since the error has proven to be much smaller on that
    platform, about 0,3%. (Now I have win98). (Still software solution
    would be a cheaper trick to play.)

  8. Default Re: Timing problem

    Hi again!

    I found one library (http://www.vbaccelerator.com/codelib...r/hirestmr.htm)
    and in the callback function TimerProc, I fount this comment:
    ' The only functions you are allowed to call
    ' during a High-resolution timer event are
    ' PostMessage, timeGetSystemTime, timeGetTime,
    ' timeSetEvent, timeKillEvent,
    ' midiOutShortMsg, midiOutLongMsg,
    ' and OutputDebugString.

    and then he preformes the line:
    PostMessage m_hWnd, MyTimerMessage, 0, 0

    I also got my code to work when I removed the Form1.print and when I
    added for instance
    form1.textbox.text = "Andreas"
    it worked. But
    form1.textbox.text = "Andreas" & rnd(5)
    did _not_ work. Now I can believe that this is for the reason
    mentioned in the comment above.

    I will try to firgure out this new library, and give this MM timer one
    more shot! I let you know tomorrow what my results are. : )

    /Andreas Lundgren

    "Murphy McCauley" <MurphyAt@AtConstantThoughtDot.DotCom> wrote in message news:<BBAnb.6582$Is.3050@newssvr27.news.prodigy.com>...
    > "Andreas" <d99alu@efd.lth.se> wrote in message
    > news:f7cd4365.0310270108.5c532d88@posting.google.com...
    > > 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.)
    > >
    > > Do you see any direct errors in my code?

    >
    > I believe the MM timer calls back from a different thread, which is very
    > problematic in VB6 (less so in VB5). It can be done, but it's nontrivial.
    > I have plans to release a library for doing "free threading" (I released a
    > demo on my website in July), but haven't gotten around to it yet. I suggest
    > you solve the problem in another way.
    >
    > If the error of 9% was problematic because it was cumulative (i.e. you're
    > trying to count to a minute by counting 60 periods of one second), you may
    > consider keeping track of the total time seperately (using the Timer
    > function, perhaps).
    >
    > Another solution is to put a callback for the MM timer in, say, a C DLL
    > which then calls SendMessage() to give a message to your form. If you don't
    > have a C compiler, you might look at LCC-Win32, which is free and decent.
    > Having this around would also help your problem of not knowing exactly what
    > VB type equivilants are -- just look in LCC's headers.
    >
    > Or you could make your app a multithreaded COM app, and create a COM
    > component that Sleep()s for a specific amount of time and then raises an
    > event or something.
    >
    > None of this will be as "tight" as using the MM timer directly, but for now,
    > I don't see a tremendous amount of options.
    >
    >
    > Murphy
    > www.ConstantThought.com


  9. Default Re: Timing problem

    BTW: Don't forget there is a huge difference in the running time between
    Compiled and NOT Compiled code.... IOW. running in the IDE...
    Something that doesn't work in the IDE might just squeak by when Compiled..

    The faster the time the less one can do in the TimerProc routine and supporting
    code that tests its results...

    Resolution OverKill.... Is it really, I mean absolutely, meaningfull to have
    timing functions that are plus/minus 1-5ms or some such thing ?¿?

    Just some food for thought ramblings..

    On 29 Oct 2003 03:04:18 -0800, d99alu@efd.lth.se (Andreas) wrote:

    >Hi again!
    >
    >I found one library (http://www.vbaccelerator.com/codelib...r/hirestmr.htm)
    >and in the callback function TimerProc, I fount this comment:
    > ' The only functions you are allowed to call
    > ' during a High-resolution timer event are
    > ' PostMessage, timeGetSystemTime, timeGetTime,
    > ' timeSetEvent, timeKillEvent,
    > ' midiOutShortMsg, midiOutLongMsg,
    > ' and OutputDebugString.
    >
    >and then he preformes the line:
    >PostMessage m_hWnd, MyTimerMessage, 0, 0
    >
    >I also got my code to work when I removed the Form1.print and when I
    >added for instance
    >form1.textbox.text = "Andreas"
    >it worked. But
    >form1.textbox.text = "Andreas" & rnd(5)
    >did _not_ work. Now I can believe that this is for the reason
    >mentioned in the comment above.
    >
    >I will try to firgure out this new library, and give this MM timer one
    >more shot! I let you know tomorrow what my results are. : )
    >
    >/Andreas Lundgren
    >


    Have a good day...

    Don

  10. Default Re: Timing problem

    Hi!

    I'm sorry to tell you, didn't get the MM-timer to work! In the code
    from the webpage below, the same number is used to set the period time
    as to set the resolution. And when I tried to change and recompile (or
    just to recompile) the new dll didn't work. I also tried the timer
    from the CCRP, but I guess I just realized that I no longer can work
    with accumulated time, but havt to find a better and more solid
    solution...

    /Andreas Lundgren

    d99alu@efd.lth.se (Andreas) wrote in message news:<f7cd4365.0310290304.101c930d@posting.google.com>...
    > Hi again!
    >
    > I found one library (http://www.vbaccelerator.com/codelib...r/hirestmr.htm)
    > and in the callback function TimerProc, I fount this comment:
    > ' The only functions you are allowed to call
    > ' during a High-resolution timer event are
    > ' PostMessage, timeGetSystemTime, timeGetTime,
    > ' timeSetEvent, timeKillEvent,
    > ' midiOutShortMsg, midiOutLongMsg,
    > ' and OutputDebugString.
    >
    > and then he preformes the line:
    > PostMessage m_hWnd, MyTimerMessage, 0, 0
    >
    > I also got my code to work when I removed the Form1.print and when I
    > added for instance
    > form1.textbox.text = "Andreas"
    > it worked. But
    > form1.textbox.text = "Andreas" & rnd(5)
    > did _not_ work. Now I can believe that this is for the reason
    > mentioned in the comment above.
    >
    > I will try to firgure out this new library, and give this MM timer one
    > more shot! I let you know tomorrow what my results are. : )
    >
    > /Andreas Lundgren
    >
    > "Murphy McCauley" <MurphyAt@AtConstantThoughtDot.DotCom> wrote in message news:<BBAnb.6582$Is.3050@newssvr27.news.prodigy.com>...
    > > "Andreas" <d99alu@efd.lth.se> wrote in message
    > > news:f7cd4365.0310270108.5c532d88@posting.google.com...
    > > > 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.)
    > > >
    > > > Do you see any direct errors in my code?

    > >
    > > I believe the MM timer calls back from a different thread, which is very
    > > problematic in VB6 (less so in VB5). It can be done, but it's nontrivial.
    > > I have plans to release a library for doing "free threading" (I released a
    > > demo on my website in July), but haven't gotten around to it yet. I suggest
    > > you solve the problem in another way.
    > >
    > > If the error of 9% was problematic because it was cumulative (i.e. you're
    > > trying to count to a minute by counting 60 periods of one second), you may
    > > consider keeping track of the total time seperately (using the Timer
    > > function, perhaps).
    > >
    > > Another solution is to put a callback for the MM timer in, say, a C DLL
    > > which then calls SendMessage() to give a message to your form. If you don't
    > > have a C compiler, you might look at LCC-Win32, which is free and decent.
    > > Having this around would also help your problem of not knowing exactly what
    > > VB type equivilants are -- just look in LCC's headers.
    > >
    > > Or you could make your app a multithreaded COM app, and create a COM
    > > component that Sleep()s for a specific amount of time and then raises an
    > > event or something.
    > >
    > > None of this will be as "tight" as using the MM timer directly, but for now,
    > > I don't see a tremendous amount of options.
    > >
    > >
    > > Murphy
    > > www.ConstantThought.com


+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Re: What the problem with my timing recovery programme?
    By Application Development in forum DSP
    Replies: 0
    Last Post: 06-30-2007, 09:27 PM
  2. Timing problem on (overly) complex page.
    By Application Development in forum Javascript
    Replies: 2
    Last Post: 06-26-2007, 09:36 AM
  3. Cox of timing problem?
    By Application Development in forum verilog
    Replies: 5
    Last Post: 04-11-2006, 08:24 AM
  4. Re: C# UDP socket timing problem...
    By Application Development in forum Javascript
    Replies: 0
    Last Post: 07-15-2005, 02:29 PM
  5. Re: C# UDP socket timing problem...
    By Application Development in forum Javascript
    Replies: 0
    Last Post: 07-15-2005, 09:21 AM