Copyright © 2006-2018 MultiMedia Soft

Events for Visual Basic 6 COM interoperability

Previous pageReturn to chapter overviewNext page

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 InitRecordingSystem 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 recorder through the OnRecorderEvents event handler when a recording session is started and stopped:

 

Visual Basic 6

 

' declare the API

Public WithEvents m_SoundRecorderApi As AudioSoundRecorderApi.AudioSoundRecorderApiObj

 

Private Sub m_SoundRecorderApi_OnRecorderEvents(ByVal nEvent As enumRecorderEvents, _

       ByVal nData1 As Long, ByVal nData2 As Long, _

       ByVal nDataHigh3 As Long, ByVal nDataLow3 As Long, _

       ByVal nDataHigh4 As Long, ByVal nDataLow4 As Long _

       )

   Select Case nEvent

       Case enumRecorderEvents.enumRecorderEvents_EV_REC_START:

           Debug.Print "Recording started"

       Case enumRecorderEvents.enumRecorderEvents_EV_REC_STOP:

           If nData1 = 1 Then

               MsgBox "Recording session completed"

           Else

               MsgBox "Recording session failed due to error " & m_SoundRecorderApi.LastError

           End If

   End Select

End Sub

 

Private Sub Form_Load()

  ' instance the API

   Set m_SoundRecorderApi = New AudioSoundRecorderApi.AudioSoundRecorderApiObj

     

  ' init the control

   m_SoundRecorderApi.InitRecordingSystem

 

  ' enable events for COM clients like VB6

   m_SoundRecorderApi.COMEventsEnable

 

  ' start a recording session from the system default recording device

   m_audioRecorderAPI.StartFromDirectSoundDevice (0, 0, "c:\myrecording.mp3")

 

  ... do other stuffs

 

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_SoundRecorderApi" which was originally declared with the "WithEvents" attribute) followed by the underscore "_" character and by the name of the event (in this case "OnRecorderEvents") and related parameters.