title: How to mute microphone in Windows 7 with C/C++?
body: <p>I made a program to mute microphone using WinAPI and it seems to work perfectly in Windows XP but doesn't do a thing in Windows 7. Is it possible to control microphone volume or mute with WinAPI in Windows 7?</p>
  
  <pre><code>void setVolume(DWORD volume) {
  HMIXER mixer;
  
  if (mixerOpen(&amp;mixer, 0, 0, 0, 0) != MMSYSERR_NOERROR) {
      MessageBoxW(NULL, L"Error: mixerOpen()", NULL, MB_ICONHAND);
      return;
  }
  
  // Get the line info
  MIXERCAPS mixcaps;
  MIXERLINE mixerLine;
  mixerGetDevCaps(0, &amp;mixcaps, sizeof(MIXERCAPS));
  mixerLine.cbStruct = sizeof(MIXERLINE);
  mixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
  mixerLine.dwSource = 0;
  mixerLine.dwDestination = 0;
  
  if (mixerGetLineInfo(reinterpret_cast&lt;HMIXEROBJ&gt;(mixer), &amp;mixerLine, MIXER_GETLINEINFOF_SOURCE)
      != MMSYSERR_NOERROR) {
          MessageBoxW(NULL, L"Error: mixerGetLineInfo()", NULL, MB_ICONHAND);
          return;
  }
  
  // Get control for mixerline
  MIXERCONTROL mixerCtrl;
  MIXERLINECONTROLS mixerLineCtrl;
  
  mixerLineCtrl.cbStruct = sizeof(MIXERLINECONTROLS);
  mixerLineCtrl.dwLineID = mixerLine.dwLineID;
  mixerLineCtrl.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
  mixerLineCtrl.cControls = 1;
  mixerLineCtrl.pamxctrl = &amp;mixerCtrl;
  mixerLineCtrl.cbmxctrl = sizeof(MIXERCONTROL);
  mixerLineCtrl.cControls = 5;
  
  if (mixerGetLineControls(reinterpret_cast&lt;HMIXEROBJ&gt;(mixer), &amp;mixerLineCtrl, MIXER_GETLINECONTROLSF_ONEBYTYPE)
      != MMSYSERR_NOERROR) {
          MessageBoxW(NULL, L"Error: mixerGetLineControls()", NULL, MB_ICONHAND);
          return;
  }
  
  // Volume..
  MIXERCONTROLDETAILS mixerCtrlDetails;
  MIXERCONTROLDETAILS_UNSIGNED mixerCtrlDetailsUnsigned;
  
  mixerCtrlDetailsUnsigned.dwValue = volume;
  mixerCtrlDetails.dwControlID = mixerCtrl.dwControlID;
  mixerCtrlDetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
  mixerCtrlDetails.cMultipleItems = 0;
  mixerCtrlDetails.paDetails = &amp;mixerCtrlDetailsUnsigned;
  mixerCtrlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
  mixerCtrlDetails.cChannels = 1;
  
  if (mixerSetControlDetails(reinterpret_cast&lt;HMIXEROBJ&gt;(mixer), &amp;mixerCtrlDetails, MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE)
      != MMSYSERR_NOERROR) {
          MessageBoxW(NULL, L"Error: mixerSetControlDetails()", NULL, MB_ICONHAND);
          return;
  }
  
  mixerClose(mixer);
  }
  </code></pre>