public static extern int mixerGetLineInfoA(int hmxobj, ref VolumeStructures.MixerLineStruct pmxl, int fdwInfo);
/// <summary> /// method to retrieve a mixer control /// </summary> /// <param name="hmxObj"></param> /// <param name="type"></param> /// <param name="ctrlType"></param> /// <param name="mixerCtrl"></param> /// <param name="curVolume"></param> /// <returns></returns> private static bool GetSystemMixer(int hmxObj, int type, int ctrlType, out VolumeStructures.MixerStruct mixerCtrl, out int curVolume) { //create our method level variables int details; bool bReturn; curVolume = -1; //create our struct objects VolumeStructures.LineControlStruct lineControls = new VolumeStructures.LineControlStruct(); VolumeStructures.MixerLineStruct line = new VolumeStructures.MixerLineStruct(); VolumeStructures.MixerDetailStruct mcDetails = new VolumeStructures.MixerDetailStruct(); VolumeStructures.UnsignedMixerDetailStruct detailsUnsigned = new VolumeStructures.UnsignedMixerDetailStruct(); //create a new mixer control mixerCtrl = new VolumeStructures.MixerStruct(); //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 = WinXPSystem.mixerGetLineInfoA(hmxObj, 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(VolumeStructures.MixerStruct)); //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 mixerCtrl.cbStruct = mcSize; // Get the control details = WinXPSystem.mixerGetLineControlsA(hmxObj, 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 mixerCtrl = (VolumeStructures.MixerStruct)Marshal.PtrToStructure(lineControls.pamxctrl, typeof(VolumeStructures.MixerStruct)); } else { bReturn = false; } int mcDetailsSize = Marshal.SizeOf(typeof(VolumeStructures.MixerDetailStruct)); int mcDetailsUnsigned = Marshal.SizeOf(typeof(VolumeStructures.UnsignedMixerDetailStruct)); mcDetails.cbStruct = mcDetailsSize; mcDetails.dwControlID = mixerCtrl.dwControlID; mcDetails.paDetails = Marshal.AllocCoTaskMem(mcDetailsUnsigned); mcDetails.cChannels = 1; mcDetails.item = 0; mcDetails.cbDetails = mcDetailsUnsigned; details = WinXPSystem.mixerGetControlDetailsA(hmxObj, ref mcDetails, VolumeConstants.MIXER_GETCONTROLDETAILSF_VALUE); detailsUnsigned = (VolumeStructures.UnsignedMixerDetailStruct)Marshal.PtrToStructure(mcDetails.paDetails, typeof(VolumeStructures.UnsignedMixerDetailStruct)); curVolume = detailsUnsigned.dwValue; return(bReturn); } bReturn = false; return(bReturn); }