Visual Basic 6 function "volume_get_waveout"

Go back

Below you'll find the source for the Visual Basic 6 function volume_get_waveout.

Attribute VB_Name = "modVolumeGetWaveout"
' This function is downloaded from:
' http://www.stefanthoolen.nl/archive/vb6-functions/
' 
' You may freely distribute this file but please leave all comments, including this one, in it.
' 
' @Author Stefan Thoolen <mail@stefanthoolen.nl>

Option Explicit

Private Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long

''
' Gets the volume for the left and right channel
' @param    byte    chleft          Will be filled with the volume of the left channel (0 to 255)
' @param    byte    chright         Will be filled with the volume of the right channel (0 to 255)
' @param    long    device_id       If a computer has more then one audio device, you could use this to specify another
' @return   boolean                 True on success, false on failure
' @author   Stefan Thoolen <mail@stefanthoolen.nl>
Public Function volume_get_waveout(ByRef chleft As Byte, ByRef chright As Byte, Optional ByVal device_id As Long = 0) As Boolean
    Dim l As Long
    If waveOutGetVolume(device_id, l) <> 0 Then Exit Function
    chleft = CLng("&h" & Left(Hex(l), 4)) / 65535 * 255
    chright = CLng("&h" & Right(Hex(l), 4)) / 65535 * 255
    volume_get_waveout = True
End Function