Declare Function auxGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
auxGetVolume retrieves the current volume setting for an auxiliary audio device. This function will retreive the volume whether the device supports dual-channel volume control or not.
If an error occured, the function returns a non-zero error code. If successful, the function returns 0.
None.
' 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
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: September 10, 1999
This page is copyright © 1999 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/a/auxgetvolume.html