Copyright © 2006-2023 MultiMedia Soft

Adding the API to a Visual Basic 6 project

Previous pageReturn to chapter overviewNext page

The .NET runtime allows unmanaged COM aware clients to seamlessly access .NET Components through the "COM Interoperability" and through the tools provided by the framework. This ensures that COM aware clients can talk to .NET components, as if they were talking to classic COM Components: "Audio Sound Recorder API for .NET" API allows this interoperability with Visual Basic 6 through a certain number of steps.

 

The first step is to add a reference to the API: after having loaded your Visual Basic 6 project, select the "Project\References..." menu item; on the "References" form, scroll down the list of installed references until you find "Audio Sound Recorder API for .NET"

 

 

As you can see there are two versions of the API:

 

1.the one ending with "v2" refers to the AudioSoundRecorderApi.dll assembly which is compiled against version 2.0 of the .NET framework: this means that the target machine will need the presence of version 3.5 of the .NET framework in order to allow the container application to run; in case it shouldn't be available, the Windows system will raise a message allowing the possibility to proceed with the related installation.
2.the one ending with "v4" refers to the AudioSoundRecorderApi.dll assembly which is compiled against version 4 of the .NET framework, allowing to run on Windows systems where version 3.5 of the .NET framework is not installed by default (as seen for Windows 8 and 10) the code to use would be very similar:

 

Decide which best fits your need and check the respective checkbox, then press the "OK" button.

 

Declare the API as a global variable inside the code of the form that will use it:

 

Visual Basic 6

 

' declare the API

Public WithEvents SoundRecorderApi As AudioSoundRecorderApi.AudioSoundRecorderApiObj

 

 

where "SoundRecorderApi" represents our global variable: you may obviously use a name of your choice.

The "WithEvents" statement allows the application to receive events from the API through COM interoperability: see the Events for Visual Basic 6 COM interoperability section for a list of supported events and for related guidelines.

 

On the loading of your application's form, instance and initialize the API:

 

Visual Basic 6

 

' instance the API

Set SoundRecorderApi = New AudioSoundRecorderApi.AudioSoundRecorderApiObj

 

' init the control

SoundRecorderApi.InitRecordingSystem

 

' enable management of recorder's events for COM clients like VB6 (callback delegates functions are not managed correctly by VB6)

SoundRecorderApi.COMEventEnable enumEventTypesRec_EVENT_TYPE_RECORDER

 

 

The next optional step is to allow the client application to be informed about events occurring inside the API. For example we could need to be informed the status of the recorder:

 

Visual Basic 6

 

Private Sub 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

           Debug.Print "Recording Stopped"

   End Select

End Sub

 

 

At this point you could add all of the needed code in order to allow the API loading and editing audio files: see the How to use the API in your projects tutorial for related guidelines.

 

The final step, immediately before exiting the client application, is to dispose the API

 

Visual C++

 

' dispose the API and all of the allocated resources

SoundRecorderApi.Dispose

 

 

 

If you are a Visual Basic 6 developer, you certainly know that VB6 is built internally with Unicode support but all of its custom controls are only ANSI compliant, meaning that you will get a series of "???" when inserting Unicode characters inside a label control or inside a textbox. If your application needs to display Unicode characters on user interface elements, the unique alternative is using the "Microsoft Forms 2.0" (FM20.DLL) ActiveX control which comes with a set of Unicode compliant controls.

 

As a second VB6 issue, the "Microsoft Common Dialog Control" (ComDlg32.ocx), used to display common dialogs for open and save operations on files, is not Unicode compliant as well and Microsoft didn't give any alternative ActiveX control for this purpose; for this reason we have added to our control a set of methods which allows selecting files containing Unicode characters:

 

CommonDialogShowOpen allows browsing a file to open
CommonDialogGetInfoFromLastOpen allows obtaining details about the filename chosen for opening through a previous call to the CommonDialogShowOpen method
CommonDialogShowSave allows browsing a file to save
CommonDialogGetInfoFromLastSave allows obtaining details about the filename chosen for saving through a previous call to the CommonDialogShowSave method