#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;*/
}