1 Attachment(s)
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:
Option Explicit
Private Sub btn1_Click()
Dim frm As New frmCalc
frm.Visible = True
End Sub
frmCalc:
VB Code:
Option Explicit
Dim WithEvents dlt As DLLT1
Private Sub form_load()
Set dlt = New DLLT1
lbl.Caption = "running"
Debug.Print Me.hwnd
dlt.start Me.hwnd
End Sub
Private Sub dlt_finished(ByVal result As Double)
lbl.Caption = "Result = " & result
End Sub
Code for the server is in one module and one class:
module:
VB Code:
Option Explicit
Public bolStart As Boolean
Public objClient As DLLT1
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public lngTimerID As Long
Public Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
objClient.calc
KillTimer hwnd, 1
End Sub
class (called dllt1):
VB Code:
Option Explicit
Event finished(ByVal result As Double)
Sub start(hwnd As Long)
Set objClient = Me
bolStart = True
SetTimer hwnd, 1, 1500, AddressOf TimerProc
End Sub
Sub calc()
Dim res As Double
If bolStart = True Then
Randomize
res = (2 + Rnd * 3)
RaiseEvent finished(res)
bolStart = False
End If
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