' This code is licensed according to the terms and conditions listed here.
' Display the current volume setting of whatever device happens
' to be auxiliary audio device 0. This example identifies whether the
' device has dual-channel volumes or not.
Dim auxinfo As AUXCAPS ' receives information about the device
Dim numvols As Long ' identifies number of volumes on the device
Dim lrvol As Long ' volumes of both channels (or just the overall volume)
Dim lvol As Integer, rvol As Integer ' volumes of left and right channels
Dim retval As Long ' return value
' Figure out whether the device has one or two volume settings.
retval = auxGetDevCaps(0, auxinfo, Len(auxinfo))
If retval <> 0 Then ' error
Debug.Print "Could not access auxiliary audio device 0 -- aborting."
End ' give up
End If
If (auxinfo.dwSupport And AUXCAPS_LRVOLUME) = AUXCAPS_LRVOLUME Then
numvols = 2 ' separate left and right volumes
Else
numvols = 1 ' only one overall volume
End If
' Determine the device's current volume.
retval = auxGetVolume(0, lrvol)
' Display the current volume setting for the device.
If numvols = 2 Then
' Separate the left and right channel volumes. The next two lines look
' like an excessively complicated way of doing it, but because of a
' quirk in Visual Basic, the "obvious" way doesn't work properly.
lvol = Val("&H" & Hex(lrvol And (Not &HFFFF0000)))
rvol = (lrvol And &HFFFF0000) / &H10000
' Display the results in hexadecimal.
Debug.Print "Left Channel volume: "; Hex(lvol)
Debug.Print "Right Channel volume: "; Hex(rvol)
Else
' Extract the useful information as above, although we only want
' the low-order word (placed into lvol).
lvol = Val("&H" & Hex(lrvol And (Not &HFFFF0000)))
' Display the results in hexadecimal.
Debug.Print "Volume: "; hex(lvol) ' here, lvol is the overall volume
End If