Copyright © 2005-2019 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 DJ Studio 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 DJ Studio API for .NET"



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


1.the one ending with "v2" refers to the AudioDJStudioApi.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 AudioDJStudioApi.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 DJStudioApi As AudioDJStudioApi.AudioDJStudioApiObj



where "DJStudioApi" 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 DJStudioApi = New AudioDJStudioApi.AudioDJStudioApiObj


' init the control

DJStudioApi.InitSoundSystem 1, 0, 0, 0, 0


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




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 the status of a specific player:


Visual Basic 6


Private Sub DJStudioApi_OnPlayersEvents(ByVal nEvent As enumPlayerEvents, ByVal nPlayer As Integer, _

       ByVal nData1 As Long, ByVal nData2 As Long, ByVal fData3 As Single, _

       ByVal pBufferUnicode As Long, ByVal nBufferLength As Long)


   Select Case nEvent

       Case enumPlayerEvents.enumPlayerEvents_EV_SOUND_STOPPED

           Debug.Print "Sound stopped"

       Case enumPlayerEvents.enumPlayerEvents_EV_SOUND_PAUSED

           Debug.Print "Sound paused"

       Case enumPlayerEvents.enumPlayerEvents_EV_SOUND_PLAYING

           Debug.Print "Sound playing"

   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





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