Microsoft DirectX 8.1 (Visual Basic) |
For an application that is simply going to play sounds through the user's preferred playback device, you don't need to enumerate the available devices. When you create the DirectSound8 object by calling the DirectX8.DirectSoundCreate function, you can specify a default device. For more information, see Creating the DirectSound Object.
If you are looking for a particular kind of device, wish to offer the user a choice of devices, or need to work with two or more devices, you must enumerate the devices available on the system.
Enumeration serves three purposes:
To enumerate devices, you must first call the DirectX8.GetDSEnum method. This method creates a DirectSoundEnum8 object containing a collection of DirectSound-capable devices. Call the DirectSoundEnum8.GetCount method to ascertain the number of available devices. Information on each device is returned by the DirectSoundEnum8.GetDescription, DirectSoundEnum8.GetGuid, and DirectSoundEnum8.GetName methods, each of which takes as a parameter the index of a device within the collection.
The following sample application prints the description of each sound device:
Dim dx As New DirectX8
Dim dsenum As DirectSoundEnum8
Private Sub Form_Load()
Set dsenum = dx.GetDSEnum
For x = 1 To dsenum.GetCount
Debug.Print dsenum.GetDescription(x), " ",
Next x
End Sub
Note The first device enumerated is always called "Primary Sound Driver", and its GUID is all zeros. This device represents the preferred playback device set by the user in Control Panel. It is enumerated separately to make it easy for the application to add "Primary Sound Driver" to a list when presenting the user with a choice of devices. The primary device is also enumerated with its proper name and GUID.