Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe "Win7Volume.exe"
#Dim All
%USEMACROS = 1
#Include "mmdeviceapi.inc" ' -- Headers with COM classes declarations,
#Include "endpointvolume.inc" ' -- translated from Windows Platform SDK by José Roca
Function PBMain () As Long
Local pIMMDeviceEnumerator As IMMDeviceEnumerator
Local pIMMDevice As IMMDevice
Local pIAudioEndpointVolume As IAudioEndpointVolume
Local vol As Single
vol = Val(Command$)/100 ' -- Read value from parameter and convert to range 0..1
vol = 0.1
pIMMDeviceEnumerator = NewCom ClsId $CLSID_MMDeviceEnumerator
If IsObject(pIMMDeviceEnumerator) Then
pIMMDeviceEnumerator.GetDefaultAudioEndpoint(%EDataFlow_eRender, %ERole_eMultimedia, pIMMDevice)
If IsObject(pIMMDevice) Then
pIMMDevice.Activate($IID_IAudioEndpointVolume, %CLSCTX_ALL, ByVal %NULL, pIAudioEndpointVolume)
If IsObject(pIAudioEndpointVolume) Then
If (vol >= 0) Then
' -- We will set the volume only in case it is positive
pIAudioEndpointVolume.SetMasterVolumeLevelScalar(vol, ByVal %NULL)
End If
' -- We return the actual volume in any case
pIAudioEndpointVolume.GetMasterVolumeLevelScalar(vol)
End If
End If
End If
pIMMDeviceEnumerator = Nothing
pIMMDevice = Nothing
pIAudioEndpointVolume = Nothing
Function = vol*100 ' -- The volume, upscaled from range 0..1 to 0..100 is returned as application return code
End Function
'gbs_01445
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm