#include <Windows.h>
#include <endpointvolume.h>
#include <mmdeviceapi.h>
#include <iostream>
using namespace Std;
#define SAFE_RELEASE (Punk) \
if ((Punk) = NULL) \
{(punk)->release (); (punk) = NULL; }
#define Init_iaudioendpointvolume\
CoInitialize (NULL); \
hr = s_ok;\
hr = CoCreateInstance (__uuidof (mmdeviceenumerator), \
NULL, Clsctx_inproc_server, __uuidof (Immdeviceenumerator), (void**) &m_penumerator); \
if (SUCCEEDED (HR)) \
{\
hr = M_penumerator->getdefaultaudioendpoint (Erender, Emultimedia, &m_pdevice);
if (SUCCEEDED (HR)) \
{\
hr = M_pdevice->activate (__uuidof (iaudioendpointvolume), \
Clsctx_all, NULL, (void**) &m_pendptvolctrl); \
}\
}
#define Uninit_iaudioendppintvolume\
Safe_release (M_pendptvolctrl); \
Safe_release (m_pdevice); \
Safe_release (m_penumerator); \
CoUninitialize ();
BOOL Setsystemmute (bool bmuted = FALSE)
{
BOOL Breresult = FALSE;
Immdevice *m_pdevice = NULL;
Iaudioendpointvolume *m_pendptvolctrl = NULL;
Immdeviceenumerator *m_penumerator = NULL;
HRESULT hr = S_OK;
Init_iaudioendpointvolume;
if (SUCCEEDED (HR))
{
hr = M_pendptvolctrl->setmute (bmuted, NULL);
if (SUCCEEDED (HR))
{
Breresult = TRUE;
}
}
Uninit_iaudioendppintvolume;
return breresult;
}
BOOL getsystemmutestatus (bool& bmuted)
{
BOOL Breresult = FALSE;
Immdevice *m_pdevice = NULL;
Iaudioendpointvolume *m_pendptvolctrl = NULL;
Immdeviceenumerator *m_penumerator = NULL;
HRESULT hr = S_OK;
Init_iaudioendpointvolume;
if (SUCCEEDED (HR))
{
hr = M_pendptvolctrl->getmute (&bmuted);
if (SUCCEEDED (HR))
{
Breresult = TRUE;
}
}
Uninit_iaudioendppintvolume;
return breresult;
}
BOOL Main ()
{
BOOL bmuted = FALSE;
if (Getsystemmutestatus (bmuted))
{
cout<< "getsystemmutestatus[%d" <<bMuted<<endl;
}
Setsystemmute (TRUE);
if (Getsystemmutestatus (bmuted))
{
cout<< "getsystemmutestatus[%d" <<bMuted<<endl;
}
Setsystemmute (FALSE);
if (Getsystemmutestatus (bmuted))
{
cout<< "getsystemmutestatus[%d" <<bMuted<<endl;
}
/*int stop;
cin>>stop;*/
}
Unmute the Win7 system