public static extern int mixerGetLineInfoA(int hmxobj, ref VolumeStructs.MixerLine pmxl, int fdwInfo);
/// <summary> /// method to retrieve a mixer control /// </summary> /// <param name="i"></param> /// <param name="type"></param> /// <param name="ctrlType"></param> /// <param name="mixerControl"></param> /// <param name="currVolume"></param> /// <returns></returns> private static bool GetMixer(int i, int type, int ctrlType, out VolumeStructs.Mixer mixerControl, out int currVolume) { //create our method level variables int details; bool bReturn; currVolume = -1; //create our struct objects VolumeStructs.LineControls lineControls = new VolumeStructs.LineControls(); VolumeStructs.MixerLine line = new VolumeStructs.MixerLine(); VolumeStructs.MixerDetails mcDetails = new VolumeStructs.MixerDetails(); VolumeStructs.UnsignedMixerDetails detailsUnsigned = new VolumeStructs.UnsignedMixerDetails(); //create a new mixer control mixerControl = new VolumeStructs.Mixer(); //set the properties of out mixerline object line.cbStruct = Marshal.SizeOf(line); line.dwComponentType = type; //get the line info and assign it to our details variable details = PCWin32.mixerGetLineInfoA(i, ref line, VolumeConstants.MIXER_GETLINEINFOF_COMPONENTTYPE); //make sure we didnt receive any errors if (VolumeConstants.MMSYSERR_NOERROR == details) { int mcSize = 152; //get the size of the unmanaged type int control = Marshal.SizeOf(typeof(VolumeStructs.Mixer)); //allocate a block of memory lineControls.pamxctrl = Marshal.AllocCoTaskMem(mcSize); //get the size of the line controls lineControls.cbStruct = Marshal.SizeOf(lineControls); //set properties for our mixer control lineControls.dwLineID = line.dwLineID; lineControls.dwControl = ctrlType; lineControls.cControls = 1; lineControls.cbmxctrl = mcSize; // Allocate a buffer for the control mixerControl.cbStruct = mcSize; // Get the control details = PCWin32.mixerGetLineControlsA(i, ref lineControls, VolumeConstants.MIXER_GETLINECONTROLSF_ONEBYTYPE); //once again check to see if we received any errors if (VolumeConstants.MMSYSERR_NOERROR == details) { bReturn = true; //Copy the control into the destination structure mixerControl = (VolumeStructs.Mixer)Marshal.PtrToStructure(lineControls.pamxctrl, typeof(VolumeStructs.Mixer)); } else { bReturn = false; } int mcDetailsSize = Marshal.SizeOf(typeof(VolumeStructs.MixerDetails)); int mcDetailsUnsigned = Marshal.SizeOf(typeof(VolumeStructs.UnsignedMixerDetails)); mcDetails.cbStruct = mcDetailsSize; mcDetails.dwControlID = mixerControl.dwControlID; mcDetails.paDetails = Marshal.AllocCoTaskMem(mcDetailsUnsigned); mcDetails.cChannels = 1; mcDetails.item = 0; mcDetails.cbDetails = mcDetailsUnsigned; details = PCWin32.mixerGetControlDetailsA(i, ref mcDetails, VolumeConstants.MIXER_GETCONTROLDETAILSF_VALUE); detailsUnsigned = (VolumeStructs.UnsignedMixerDetails)Marshal.PtrToStructure(mcDetails.paDetails, typeof(VolumeStructs.UnsignedMixerDetails)); currVolume = detailsUnsigned.dwValue; return(bReturn); } bReturn = false; return(bReturn); }