Results 1 to 2 of 2

Thread: [DLL] Mute sounds on Vista

  1. #1

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    [DLL] Mute sounds on Vista

    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:
    1. #include "common.h"
    2.  
    3. BOOL MuteAudio()
    4. {
    5.     HRESULT hr;
    6.     CoInitialize(NULL);
    7.     IMMDeviceEnumerator *deviceEnumerator = NULL;
    8.     hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
    9.     if (!SUCCEEDED(hr))
    10.     {
    11.         CoUninitialize();
    12.         return FALSE;
    13.     }
    14.  
    15.     IMMDevice *defaultDevice = NULL;
    16.  
    17.     hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
    18.     deviceEnumerator->Release();
    19.     deviceEnumerator = NULL;
    20.     if (!SUCCEEDED(hr))
    21.     {
    22.         CoUninitialize();
    23.         return FALSE;
    24.     }
    25.  
    26.     IAudioEndpointVolume *endpointVolume = NULL;
    27.     hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
    28.     defaultDevice->Release();
    29.     defaultDevice = NULL;
    30.  
    31.     if (!SUCCEEDED(hr))
    32.     {
    33.         CoUninitialize();
    34.         return FALSE;
    35.     }
    36.  
    37.     // -------------------------
    38.  
    39.     endpointVolume->SetMute(TRUE, NULL);
    40.  
    41.     endpointVolume->Release();
    42.  
    43.     CoUninitialize();
    44.  
    45.     return TRUE;
    46. }
    47.  
    48. BOOL UnmuteAudio()
    49. {
    50.     HRESULT hr;
    51.  
    52.     CoInitialize(NULL);
    53.     IMMDeviceEnumerator *deviceEnumerator = NULL;
    54.     hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
    55.     if (!SUCCEEDED(hr))
    56.     {
    57.         CoUninitialize();
    58.         return FALSE;
    59.     }
    60.  
    61.     IMMDevice *defaultDevice = NULL;
    62.  
    63.     hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
    64.     deviceEnumerator->Release();
    65.     deviceEnumerator = NULL;
    66.     if (!SUCCEEDED(hr))
    67.     {
    68.         CoUninitialize();
    69.         return FALSE;
    70.     }
    71.  
    72.     IAudioEndpointVolume *endpointVolume = NULL;
    73.     hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
    74.     defaultDevice->Release();
    75.     defaultDevice = NULL;
    76.  
    77.     if (!SUCCEEDED(hr))
    78.     {
    79.         CoUninitialize();
    80.         return FALSE;
    81.     }
    82.  
    83.     // -------------------------
    84.  
    85.     endpointVolume->SetMute(FALSE, NULL);
    86.  
    87.     endpointVolume->Release();
    88.  
    89.     CoUninitialize();
    90.  
    91.     return TRUE;
    92. }

    common.h code
    C++ Code:
    1. #pragma once
    2.  
    3. #define WIN32_LEAN_AND_MEAN
    4.  
    5. #include <windows.h>
    6. #include <objbase.h>
    7. #include <mmdeviceapi.h>
    8. #include <endpointvolume.h>
    9.  
    10. #define AUDCTRL_API extern "C" __declspec(dllexport)
    11.  
    12. AUDCTRL_API BOOL MuteAudio(void);
    13. AUDCTRL_API BOOL UnmuteAudio(void);

  2. #2
    Banned
    Join Date
    Mar 2009
    Posts
    17

    Re: [DLL] Mute sounds on Vista

    wow, that is really interesting thanks for sharing it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width