The way to do this is to open the default WaveIn device using WaveInOpen
and that will get you a waveIn handle. Then you can use the mixer... APIs to select the associated mixer line.
This will be a destination line, and will have some controls (often a mute and a volume). You may be able to set these. However, this is where it gets a little complicated. There are also multiple "sources" associated with a destination (e.g. Microphone, Line In etc). These too can have volume and mute and other custom controls. You may need to experiment a little to find the control you really want to change. I have found it hard to come up with code that works reliably on both Vista and XP (it may actually be to do with your sound card drivers).
I have written managed wrappers for all these functions in NAudio which will get you part of the way. This is roughly what you want to do:
MixerLine mixerLine;
if (waveInHandle != IntPtr.Zero)
{
mixerLine = new MixerLine(waveInHandle, 0, MixerFlags.WaveInHandle);
}
else
{
mixerLine = new MixerLine((IntPtr)waveInDeviceNumber, 0, MixerFlags.WaveIn);
}
foreach (MixerControl control in mixerLine.Controls)
{
if (control.ControlType == MixerControlType.Volume)
{
// this is the volume control of the "destination"
UnsignedMixerControl volumeControl = (UnsignedMixerControl)control;
Debug.WriteLine(volumeControl.Percent.ToString());
}
}
// to examine the volume controls of the "sources":
if (source.ComponentType == MixerLineComponentType.SourceMicrophone)
{
foreach (MixerControl control in source.Controls)
{
if (control.ControlType == MixerControlType.Volume)
{
// this might be the one you want to set
}
}
}