Copyright © 2011-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 Editor 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 Editor API for .NET"

 

 

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

 

1.the one ending with "v2" refers to the AudioSoundEditorApi.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 AudioSoundEditorApi.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 SoundEditorApi As AudioSoundEditorApi.AudioSoundEditorApiObj

 

 

where "SoundEditorApi" 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 SoundEditorApi = New AudioSoundEditorApi.AudioSoundEditorApiObj

 

' init the control

SoundEditorApi.InitEditor

 

' enable editor's percentage-related events for COM clients like VB6 (callback delegates functions are not managed correctly by VB6)

SoundEditorApi.COMEventEnable enumEventTypesEdt_EVENT_TYPE_EDT_PERC

 

 

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 about percentage of advancement of sound loading and waveform analysis operations:

 

Visual Basic 6

 

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

 

   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

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

SoundEditorApi.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