Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Communicating with a DLL
Message
Information générale
Forum:
Visual Basic
Catégorie:
COM, DCOM et OLE automation
Divers
Thread ID:
00625299
Message ID:
00625346
Vues:
12
>I have a long running task that's performed by a business object ActiveX DLL installed on the same computer as the client EXE. Is there a way to get a progress status from the DLL to the EXE?
>
>FYI, the client EXE knows the maximum number of computation the DLL needs to perform on a one-by-one bases till finished. I would like to display a progress status (via progressbar) of how many have finished (1 of 100 done).

Hi John

Yes. You can raise the event from your DLL and bind the events from your EXE.
Option Explicit

Public cEventname As String, Value As Variant

Public Event SomethingHappened(ByVal cEventname As String, ByVal Value As Variant)

Public Sub FireEvent(ByVal tEventName As String, ByVal tEventValue As Variant)

cEventname = tEventName
Value = tEventValue
RaiseEvent SomethingHappened(cEventname, Value)

End Sub
This generic EventRaiser code can generate any number of recognizable custom events with just one event defined. The parameters determine what exactly happened and what the value is.
When necessary call FireEvent method and pass necessary parameters like:

myComObject.FireEvent("PROGRESSBAR_RESET")
'
'
'

myComObject.FireEvent("SHOWNAME", some_name_here)
'
myComObject.FireEvent("PROGRESSBAR_UPDATE", yourvalue_here)
Below is the code of the test form which is exactly the demo of the progress bar. Consider it rather a pseudo-code. It was working code from my VB sample for raising events from VFP COM modules, I just "converted" it back for pure VB example, but not tested this "back-converted" :) version. I hope you get an idea.
* Test form code
Option Explicit

Private WithEvents oMyCom As oMyCOM 'Declare the variable using WithEvents keyword
'which will connect the events

Private Sub Form_Initialize()
    Set oMyCom = New oMyCom 'Create your COM object
End Sub


Private Sub Form_Terminate()
    oMyCom = Nothing
    'Reset the object reference to the COM module
End Sub


Private Sub oMycom_SomethingHappened( _
ByVal tEventname As String, _
ByVal tEventValue As Variant)
    
    If tEventname = "PROGRESSBAR_RESET" Then
        ShapeBar.Tag = tEventValue
        'reset the progress bar
    End If
    
    If tEventname = "SHOWNAME" Then
        lblLastName.Caption = tEventValue
        'Show the current person name processed
        'in the COM module
    End If
    
    If tEventname = "PROGRESSBAR_UPDATE" Then
        ShapeBar_SetValue (tEventValue)
    End If
   
   
    If tEventname = "ERROR" Then
        MsgBox (tEventValue)
    End If
    
End Sub

Private Sub cmdProcess_Click()
    Call oMyCom.Process1
    ' Run some process in VFP COM module
End Sub

Private Sub ShapeBar_SetValue(ByVal Value As Variant)
Static nWidth
Dim nPercent, nTotal
nTotal = Val(ShapeBar.Tag)
If nTotal > 0 Then
    nPercent = Int(Value / Val(ShapeBar.Tag) * 100)
    ShapeBar.Width = Int(nPercent / 100 * _
    (ShapeUnder.Width - 15))
    lblPercent.Caption = CStr(nPercent) & "%"
End If

End Sub
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform