# VBForums CodeBank > CodeBank - C++ >  [DLL] Mute sounds on Vista

## Paul M

Here is the brilliant code to the frustrating issue with muting sounds on vista due to everything changing. This was made with some help from Rob Paveza. As you can see the functions exported are simply MuteAudio() and UnmuteAudio().

AudioControl.cpp code

C++ Code:
#include "common.h"
 BOOL MuteAudio()
{
    HRESULT hr;
    CoInitialize(NULL);
    IMMDeviceEnumerator *deviceEnumerator = NULL;
    hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
    if (!SUCCEEDED(hr)) 
    {
        CoUninitialize();
        return FALSE;
    }
     IMMDevice *defaultDevice = NULL;
     hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
    deviceEnumerator->Release();
    deviceEnumerator = NULL;
    if (!SUCCEEDED(hr))
    {
        CoUninitialize();
        return FALSE;
    }
     IAudioEndpointVolume *endpointVolume = NULL;
    hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
    defaultDevice->Release();
    defaultDevice = NULL; 
     if (!SUCCEEDED(hr)) 
    {
        CoUninitialize();
        return FALSE;
    }
     // -------------------------
     endpointVolume->SetMute(TRUE, NULL);
     endpointVolume->Release();
     CoUninitialize();
     return TRUE;
}
 BOOL UnmuteAudio()
{
    HRESULT hr;
     CoInitialize(NULL);
    IMMDeviceEnumerator *deviceEnumerator = NULL;
    hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
    if (!SUCCEEDED(hr)) 
    {
        CoUninitialize();
        return FALSE;
    }
     IMMDevice *defaultDevice = NULL;
     hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
    deviceEnumerator->Release();
    deviceEnumerator = NULL;
    if (!SUCCEEDED(hr))
    {
        CoUninitialize();
        return FALSE;
    }
     IAudioEndpointVolume *endpointVolume = NULL;
    hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
    defaultDevice->Release();
    defaultDevice = NULL; 
     if (!SUCCEEDED(hr)) 
    {
        CoUninitialize();
        return FALSE;
    }
     // -------------------------
     endpointVolume->SetMute(FALSE, NULL);
     endpointVolume->Release();
     CoUninitialize();
     return TRUE;
}

common.h code

C++ Code:
#pragma once
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
#include <objbase.h>
#include <mmdeviceapi.h>
#include <endpointvolume.h>
 #define AUDCTRL_API extern "C" __declspec(dllexport)
 AUDCTRL_API BOOL MuteAudio(void);
AUDCTRL_API BOOL UnmuteAudio(void);

----------


## deepu8

wow, that is really interesting thanks for sharing it.

----------

