Results 1 to 7 of 7

Thread: Settimer won't find its timerproc???

Threaded View

  1. #1
    Helger
    Guest

    Settimer won't find its timerproc???

    I'm trying to get an activex.exe server to run with a client. So far it's only a simple test-project. I want to have it so that client and server act completely independent and have them communicate via an event in the server.

    Everything worked fine in the activex.dll variant (except that both proggies will be in the same thread of course and I don't want that).

    In the exe-version my timer doesn't trigger its timerproc. What's wrong?

    Code for Client is behind 2 forms(frmStart with one commandbutton and frmCalc with one label called lbl):

    frmStart:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub btn1_Click()
    4.  
    5. Dim frm As New frmCalc
    6.  
    7. frm.Visible = True
    8.  
    9. End Sub

    frmCalc:
    VB Code:
    1. Option Explicit
    2. Dim WithEvents dlt As DLLT1
    3.  
    4. Private Sub form_load()
    5.  
    6. Set dlt = New DLLT1
    7. lbl.Caption = "running"
    8. Debug.Print Me.hwnd
    9. dlt.start Me.hwnd
    10.  
    11. End Sub
    12.  
    13.  
    14.  
    15. Private Sub dlt_finished(ByVal result As Double)
    16.  
    17. lbl.Caption = "Result = " & result
    18.  
    19. End Sub

    Code for the server is in one module and one class:

    module:
    VB Code:
    1. Option Explicit
    2.  
    3. Public bolStart As Boolean
    4. Public objClient As DLLT1
    5.  
    6. Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    7. Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    8. Public lngTimerID As Long
    9.  
    10. Public Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
    11.  
    12.     objClient.calc
    13.     KillTimer hwnd, 1
    14.  
    15. End Sub

    class (called dllt1):
    VB Code:
    1. Option Explicit
    2. Event finished(ByVal result As Double)
    3.  
    4. Sub start(hwnd As Long)
    5.  
    6. Set objClient = Me
    7. bolStart = True
    8. SetTimer hwnd, 1, 1500, AddressOf TimerProc
    9.  
    10. End Sub
    11.  
    12. Sub calc()
    13. Dim res As Double
    14.  
    15. If bolStart = True Then
    16.     Randomize
    17.     res = (2 + Rnd * 3)
    18.     RaiseEvent finished(res)
    19.     bolStart = False
    20. End If
    21.  
    22. End Sub

    In case anyone wants to experiment with these projects I added them in a zip file. You need to run the 2 proj. in two instances of VB6. First run the server then make a reference to it in the client.

    thx,

    Helger
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width