Muting and UnMuting the Windows Volume using Visual Basic 6

Is there an API or simple set of commands I can use to Mute all of the audio output from a MS Windows PC system, and then easily UnMute?

I would like a command set or API which has the same effect as clicking the "Mute" Checkbox within the windows volume control displayed in the taskbar.

I have tried the "auxSetVolume" function from the winmm.dll file, to set the volume to zero, however it does not appear to work. I may however have been using incorrect syntax.

Ideally it would be nice if there was a simple API or command such as "auxMuteVolume" and "auxUnMuteVolume", but alas things rarely work out that easily.

Example code for Visual Basic 6 would be useful...

Thankyou.
LoquerionAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
The API's make use of custom type structures.  Your best off just copying and pasting everything below the

' ----------------------------------------------------------------------
' Module Code
' ----------------------------------------------------------------------

mark into a module even if you are not going to use all of it.  Try creating the project as I described it to see how it works and then try paring it down to the bare minimum after that.

Idle_Mind
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Take a look at the Accepted Answer I posted here: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20923876.html

Regards,

Idle_Mind
0
 
LoquerionAuthor Commented:
I have had a look at those links, and the ones that link from there... although I feel I am now closer to the answer, it still eludes me:

Am I right in thinking that I should be declaring two DLL proceedures from "winmm.dll" in a module something like:

----------
Public Declare Function OpenMixer Lib "winmm.dll" (ByVal MixerNumber As Long) As Long

Public Declare Function SetMute Lib "winmm.dll" (Control As MUTE_CONTROL, ByVal MuteState As Boolean) As Boolean
----------

then just calling them where I need them as:

----------
Public Sub MuteVolume()

     OpenMixer(0)
     SetMute(SPEAKER_MUTE, True)

End Sub
----------

because that doesnt work... I get an error "Cannot find DLL entry point OpenMixer in winmm.dll" on calling the open mixer, and I then get an error of "User-defined type not defined" on trying to compile from the SetMute...

...

I believe the code that you pointed to:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20923876.html

...has the ability to do what I need, but I may be Hamming up the module declarations as they are not actually set out word for word in code.


** I do not understand what the "Control As MUTE_CONTROL" actually does... i think that my problem my lie there...
0
 
LoquerionAuthor Commented:
right... i will try that, but is it not possible to just reference that API, including its custom structures straight from the DLL? It just seems, (and maybe this is just how it is), a little silly to have to include a large WHACK of a DLL file in your project instead of referencing it...

lol... i think i know what you mean though... and i recall that there were some errors in VB when it comes to parsing DLL files... i will give it a go and get back to you.

**

ok, i lied... i tried it there now, and it works... so worst case scenario i will have a slightly larger source code printout than i would have liked, but it does work... i would however like to try and get it working with just a few DLL referencesinstead of a cut/paste job of the whole of "winmm.dll"...

Thanks again, will be in touch...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.