Copyright © 2011-2018 MultiMedia Soft

Events for Visual Basic 6 COM interoperability

Previous pageReturn to chapter overviewNext page

As mentioned inside the tutorial How to synchronize the container application with the API, Visual Basic 6 results unreliable when dealing with delegates and callbacks in general so, when using the API in conjunctions with this development environment, a set of COM compatible events is provided.

 

In order to enable the usage of the provided events you simply need to invoke the COMEventsEnable method immediately after initializing the API through the InitEditor method, then you need to manually enter the event management routine.

 

Inside the snippet below you can see an example of management of events generated by the editor through the OnPercentage event handler; the text of a label is modified when monitored events are reported and a progress bar is managed as well to inform about operations advancement:

 

Visual Basic 6

 

' declare the API

Public WithEvents m_SoundEditorApi As AudioSoundEditorApi.AudioSoundEditorApiObj

 

Private Sub m_SoundEditorApi_OnPercentage(ByVal nOperation As enumOperationsWithPercentage, ByVal nPercentage As Integer)

   If ProgressBar1.Value = nPercentage Then

      ' no change

       Exit Sub

   End If

   ProgressBar1.Visible = True

   ProgressBar1.Value = nPercentage

 

   If nOperation = enumOperationsWithPercentage_OPERATION_SOUND_LOADING Then

       LabelStatus.Caption = "Status: Loading... " & nPercentage & "%"

   ElseIf nOperation = enumOperationsWithPercentage_OPERATION_WAVE_ANALYSIS Then

       LabelStatus.Caption = "Status: Analyzing waveform... " & nPercentage & "%"

   End If

 

   ProgressBar1.Refresh

   LabelStatus.Refresh

End Sub

 

Private Sub Form_Load()

  ' instance the API

   Set m_SoundEditorApi = New AudioSoundEditorApi.AudioSoundEditorApiObj

     

  ' init the control

   m_SoundEditorApi.InitEditor

 

  ' enable events for COM clients like VB6

   m_SoundEditorApi.COMEventsEnable

 

   LabelStatus.Caption = "Status: Idle"

   ProgressBar1.Visible = False

 

  ' load the new song

   m_SoundEditorApi.SetLoadingMode enumLoadingModes_LOAD_MODE_NEW

   Dim nResult As enumErrorCodes

   nResult = m_SoundEditorApi.LoadSound(strPathname)

   If nResult <> enumErrorCodes_ERR_NOERROR Then

       MsgBox "Cannot load the file due to the following error: " & nResult

       Exit Sub

   End If

 

   ProgressBar1.Value = 0

 

  ' request full waveform analysis using default resolution

   m_SoundEditorApi.DisplayWaveformAnalyzerGet().AnalyzeFullSound

 

   ProgressBar1.Visible = False

   LabelStatus.Caption = "Status: Idle"

 

End Sub

 

 

as seen for regular ActiveX controls, the name of the event management routine is made of a number of parts: the name of the component (in this case "m_SoundEditorApi" which was originally declared with the "WithEvents" attribute) followed by the underscore "_" character and by the name of the event (in this case "OnPercentage") and related parameters.