Jump to content
PeterVerbeek

SoundGetWaveVolume on Windows Vista, 7, 8, 8.1 and 10

Recommended Posts

Hi Guys,

I've noticed that the SoundGetWaveVolume UDF in an older topic isn't working on Windows Vista, 7, 8, 8.1 and 10. It's probably a Windows XP UDF. The UDF below does work. It successfully returns the volume set by SoundSetWaveVolume. It might need checking by the AutoIt community for some synthax finetuning.

; #FUNCTION# ====================================================================================================================
; Name...........: _SoundGetWaveVolume
; Description....: Returns app volume of script, Windows Vista, 7, 8, 10 only
; Syntax.........: _SoundGetWaveVolume([$iValueOnError = -1])
; Parameters.....: $iValueOnError           - Value to return when an error occurs
; Return values..: App volume of script or $iValueOnError at an error
; Error values...: @error = 1               - Unable to create Struct
;                  @error = 2               - Dll file not found
;                  @error = 3               - Wrong call so not on Windows Vista, 7, 8 or 10
;                  @error = 4               - Internal error, array not returned
;                  @error = 5               - Volume wasn't received
;                  @error = 6               - Volume couldn't read
; Author.........: Peter Verbeek
; Modified.......:
; ===============================================================================================================================
Func _SoundGetWaveVolume($iValueOnError = -1)
    Local $LPDWORD,$aMMRESULT,$iVolume

    $LPDWORD = DllStructCreate("dword")
    If @error <> 0 Then
        SetError(1)                                             ; 1 = unable to create Struct
        Return $iValueOnError
    EndIf
    ; get app volume of this script
    $aMMRESULT = DllCall("winmm.dll","uint","waveOutGetVolume","ptr",0,"long_ptr",DllStructGetPtr($LPDWORD))
    Switch @error
        Case 1
            SetError(2)                                         ; 2 = dll file not found
            Return $iValueOnError
        Case 2,3,4,5
            SetError(3)                                         ; 3 = wrong call so not on Windows Vista, 7, 8 or 10
            Return $iValueOnError
    EndSwitch
    If not IsArray($aMMRESULT) Then
        SetError(4)                                             ; 4 = internal error, array not returned
        Return $iValueOnError
    EndIf
    If $aMMRESULT[0] <> 0 Then
        SetError(5)                                             ; 5 = volume wasn't received
        Return $iValueOnError
    EndIf
    $iVolume = DllStructGetData($LPDWORD,1)
    If @error <> 0 Then
        SetError(6)                                             ; 6 = volume couldn't read
        Return $iValueOnError
    EndIf
    Return Round(100*$iVolume/4294967295)                       ; return in range 0 to 100 as SoundSetWaveVolume()
EndFunc

 

Edited by PeterVerbeek
error codes in function header added

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Kelvin44
      WiFi Disconnects Automatically Windows 10 / 8 / 7 Laptop. This video guide very help to me
    • By Drac89
      How do i pass the IE handle to an active windows authentication prompt when the IE shows it is " waiting " , right now it is nt detecting the windows security prompt
      I used the below to wait for it to load until the 60ms timeout but still it isnt working  :
       
      #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
      #AutoIt3Wrapper_Outfile=ps_test.exe
      #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
      #include <Constants.au3>
      #include <IE_v1.au3>
      If $CmdLine[0] < 2 Then
         MsgBox($MB_OK, "Usage", "ps_WAN <username> <password>")
      Else
         wan($CmdLine[1], $CmdLine[2])
      EndIf
      Func wan($email, $password)
       $oIE = _IECreate()
      $ieo=_IENavigate($oIE, "https://cccc")
      _IELoadWait($ieo,0,60)
       Local $hWnd = WinExists("Windows Security")
      if $hWnd = 0 Then
         MsgBox($MB_OK, "Usage", "timeout")
         EndIf
      ControlFocus("Windows Security", "", "[CLASS:DirectUIHWND]")
      ControlFocus("Windows Security", "", "[CLASS:Edit; INSTANCE:1]")
       

    • By Iznogoud
      Hi,
      Does anyone knows why this command doesn't work?
      Run(@ComSpec & " /c " & "devcon.exe hwids * | findstr /R ""1050&PID_0114&REV_0340&MI_01"" || (rundll32.exe user32.dll, LockWorkStation)", "", "") This is the command in commandline:
      devcon.exe hwids * | findstr /R "1050&PID_0114&REV_0340&MI_01" && (echo USB Device is connected) || (rundll32.exe user32.dll, LockWorkStation) This works, but i want to convert this to AutoIT, but it doesn't work.
       
      In short what i am trying to accomplish is that a script checks every 1 sec. if there is an USB device plugged in and if not ( so it is removed ) it will lock Windows OS.
      Can someone help me with this?
    • By VITSUSA
      I am using window XP in my desktop, so I want to convert basic disk to a dynamic disk, so how it is possible?
    • By XaelloNegative
      Hi,
      I'm currently saving process time stamps of my employer's other employees and saving it in a text document as data storage. However, my employer wants it to be processed in a day to day basis to generate their average process time per day. How can I compare today from yesterday and so on and so forth with the succeeding days? Whats the best approach to this?
      Thank you.
      ~XN~
×
×
  • Create New...