private static WinXpDllInterface.MIXER InnerGetMixer(int i, uint type, uint ctrlType, out int currVolume) { currVolume = -1; WinXpDllInterface.LINECONTROLS mlc = new WinXpDllInterface.LINECONTROLS(); WinXpDllInterface.MIXERLINE mxl = new WinXpDllInterface.MIXERLINE(); WinXpDllInterface.MIXERDETAILS xdl = new WinXpDllInterface.MIXERDETAILS(); WinXpDllInterface.UMIXERDETAILS uxdl = new WinXpDllInterface.UMIXERDETAILS(); WinXpDllInterface.MIXER mixerControl = new WinXpDllInterface.MIXER(); mxl.cbStruct = (uint)Marshal.SizeOf(mxl); mxl.dwComponentType = (uint)type; int details = WinXpDllInterface.mixerGetLineInfoA(i, ref mxl, WinXpDllInterface.MIXER_GETLINEINFOF_COMPONENTTYPE); if (WinXpDllInterface.MMSYSERR_NOERROR == details) { int mcSize = 152; int control = Marshal.SizeOf(typeof(WinXpDllInterface.MIXER)); mlc.pamxctrl = Marshal.AllocCoTaskMem(mcSize); mlc.cbStruct = (uint)Marshal.SizeOf(mlc); mlc.dwLineID = mxl.dwLineID; mlc.dwControl = (uint)ctrlType; mlc.cControls = 1; mlc.cbmxctrl = (uint)mcSize; mixerControl.cbStruct = mcSize; details = WinXpDllInterface.mixerGetLineControlsA(i, ref mlc, WinXpDllInterface.MIXER_GETLINECONTROLSF_ONEBYTYPE); bool result = WinXpDllInterface.MMSYSERR_NOERROR == details; if (result) { mixerControl = (WinXpDllInterface.MIXER)Marshal.PtrToStructure(mlc.pamxctrl, typeof(WinXpDllInterface.MIXER)); int mcDetailsSize = Marshal.SizeOf(typeof(WinXpDllInterface.MIXERDETAILS)); int mcDetailsUnsigned = Marshal.SizeOf(typeof(WinXpDllInterface.UMIXERDETAILS)); xdl.cbStruct = mcDetailsSize; xdl.dwControlID = mixerControl.dwControlID; xdl.paDetails = Marshal.AllocCoTaskMem(mcDetailsUnsigned); xdl.cChannels = 1; xdl.item = 0; xdl.cbDetails = mcDetailsUnsigned; details = WinXpDllInterface.mixerGetControlDetailsA(i, ref xdl, WinXpDllInterface.MIXER_GETCONTROLDETAILSF_VALUE); uxdl = (WinXpDllInterface.UMIXERDETAILS)Marshal.PtrToStructure(xdl.paDetails, typeof(WinXpDllInterface.UMIXERDETAILS)); currVolume = uxdl.dwValue; return(mixerControl); } } return(mixerControl); }
private static WinXpDllInterface.MIXERINFO InnerGetMixerInfo() { WinXpDllInterface.MIXERLINE mxl = new WinXpDllInterface.MIXERLINE(); WinXpDllInterface.LINECONTROLS mlc = new WinXpDllInterface.LINECONTROLS(); mxl.cbStruct = (uint)Marshal.SizeOf(typeof(WinXpDllInterface.MIXERLINE)); mlc.cbStruct = (uint)Marshal.SizeOf(typeof(WinXpDllInterface.LINECONTROLS)); WinXpDllInterface.mixerGetLineInfo(0, ref mxl, WinXpDllInterface.MIXER_OBJECTF_MIXER | WinXpDllInterface.MIXER_GETLINEINFOF_DESTINATION); mlc.dwLineID = mxl.dwLineID; mlc.cControls = mxl.cControls; mlc.cbmxctrl = (uint)Marshal.SizeOf(typeof(WinXpDllInterface.MIXERCONTROL)); mlc.pamxctrl = Marshal.AllocHGlobal((int)(mlc.cbmxctrl * mlc.cControls)); WinXpDllInterface.mixerGetLineControls(0, ref mlc, WinXpDllInterface.MIXER_OBJECTF_MIXER | WinXpDllInterface.MIXER_GETLINECONTROLSF_ALL); WinXpDllInterface.MIXERINFO rtn = new WinXpDllInterface.MIXERINFO(); for (int i = 0; i < mlc.cControls; i++) { WinXpDllInterface.MIXERCONTROL mxc = (WinXpDllInterface.MIXERCONTROL)Marshal.PtrToStructure((IntPtr)((int)mlc.pamxctrl + (int)mlc.cbmxctrl * i), typeof(WinXpDllInterface.MIXERCONTROL)); switch (mxc.dwControlType) { case WinXpDllInterface.MIXERCONTROL_CONTROLTYPE_VOLUME: rtn.volumeCtl = mxc.dwControlID; rtn.minVolume = mxc.Bounds.lMinimum; rtn.maxVolume = mxc.Bounds.lMaximum; break; case WinXpDllInterface.MIXERCONTROL_CONTROLTYPE_MUTE: rtn.muteCtl = mxc.dwControlID; break; } } Marshal.FreeHGlobal(mlc.pamxctrl); return(rtn); }