Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Muting and UnMuting the Windows Volume using Visual Basic 6

Posted on 2004-04-14
4
Medium Priority
?
1,971 Views
Last Modified: 2013-11-25
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.
0
Comment
Question by:Loquerion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 10825364
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
 

Author Comment

by:Loquerion
ID: 10826532
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 150 total points
ID: 10826592
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
 

Author Comment

by:Loquerion
ID: 10826969
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

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question