dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Mute code not working in Vista

  1. #1
    Join Date
    Nov 2001
    Posts
    244

    Mute code not working in Vista

    Hi Guys,

    I'm aware Vista has a new Sound Interface, when I run the code below, it does not Mute in Vista, it works fine in XP though.

    This code Mutes the Main Volume in XP. It appears Vista wont let you mute the main volume, I think it only lets you mute the application now?

    (Using WinXP Pro and MS Visual Studio 6)


    MUTE ON/OFF CODE
    Code:
    	if (m_hMixer == NULL)
    	{
    		return FALSE;
    	}
    
    	MIXERCONTROLDETAILS_BOOLEAN mxcdMute = { lVal };
    	MIXERCONTROLDETAILS mxcd;
    	mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
    	mxcd.dwControlID = m_dwMuteControlID;
    	mxcd.cChannels = 1;
    	mxcd.cMultipleItems = 0;
    	mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
    	mxcd.paDetails = &mxcdMute;
    	if (::mixerSetControlDetails(reinterpret_cast<HMIXEROBJ>(m_hMixer),
    								 &mxcd,
    								 MIXER_OBJECTF_HMIXER |
    								 MIXER_SETCONTROLDETAILSF_VALUE)
    		!= MMSYSERR_NOERROR)
    	{
    		return FALSE;
    	}
    	
    	return TRUE;

    MIXER INITIALIZATION
    Code:
    bool MuteInit()
    {
    // get the number of mixer devices present in the system
    	int m_nNumMixers = ::mixerGetNumDevs();
    
    	m_hMixer = NULL;
    	::ZeroMemory(&m_mxcaps, sizeof(MIXERCAPS));
    
    	m_strDstLineName.Empty();
    	m_strMuteControlName.Empty();
    	m_dwMuteControlID = 0;
    
    	// open the first mixer
    	// A "mapper" for audio mixer devices does not currently exist.
    	if (m_nNumMixers != 0)
    	{
    		if (::mixerOpen(&m_hMixer,
    						0,
    						reinterpret_cast<DWORD>(this->GetSafeHwnd()),
    						NULL,
    						MIXER_OBJECTF_MIXER | CALLBACK_WINDOW)
    			!= MMSYSERR_NOERROR)
    		{
    			return FALSE;
    		}
    
    		if (::mixerGetDevCaps(reinterpret_cast<UINT>(m_hMixer),
    							  &m_mxcaps, sizeof(MIXERCAPS))
    			!= MMSYSERR_NOERROR)
    		{
    			return FALSE;
    		}
    	}
    
    	return TRUE;
    }


    Is there a new routine I need to use now?

    Maybe its all tied to DirectSound now or something?


    cheers


  2. #2
    Join Date
    Nov 2001
    Posts
    244

    Re: Mute code not working in Vista

    *bump*

  3. #3
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Mute code not working in Vista

    Using IAudioEndpointVolume interface methods (SetMute, SetMasterVolumeLevelScalar)

    How do I change the master volume in Windows Vista on Larry Osterman's WebLog.
    Regards,
    Ramkrishna Pawar

  4. #4
    Join Date
    Nov 2001
    Posts
    244

    Re: Mute code not working in Vista

    Thanks Krishnaa, I'll look into it

  5. #5
    Join Date
    Nov 2001
    Posts
    244

    Re: Mute code not working in Vista

    got Mute working now in Vista.

    here's the code if u need it (you need to add error checking though)


    Code:
    		
    // VISTA code
    		//
    
    		CoInitialize(NULL);
    		IMMDeviceEnumerator *deviceEnumerator = NULL;
    		hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator);
    		IMMDevice *defaultDevice = NULL;
    
    		hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
    		deviceEnumerator->Release();
    		deviceEnumerator = NULL;
    
    		IAudioEndpointVolume *endpointVolume = NULL;
    		hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume);
    		defaultDevice->Release();
    		defaultDevice = NULL; 
    
    		// -------------------------
    
    		endpointVolume->SetMute(TRUE, NULL);
    
    		endpointVolume->Release();
    
    		CoUninitialize();

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)