private static Win7ComInterface.IAudioEndpointVolume GetAudioEndPointVolume() { Win7ComInterface.IAudioEndpointVolume result = null; InvokeTryCatch("Win7VolumeOperate.GetAudioEndPointVolume", () => { Win7ComInterface.IMMDevice device = Device; if (device == null) { return; } const uint CLSCTX_ALL = 23u; object comEndPointVol; Guid IID_IAudioEndpointVolume = typeof(Win7ComInterface.IAudioEndpointVolume).GUID; Marshal.ThrowExceptionForHR(device.Activate(ref IID_IAudioEndpointVolume, CLSCTX_ALL, IntPtr.Zero, out comEndPointVol)); Win7ComInterface.IAudioEndpointVolume endPointVol = comEndPointVol as Win7ComInterface.IAudioEndpointVolume; if (endPointVol == null) { throw new Exception("初始化 Win7以上操作系统的 音频Com IAudioEndpointVolume 组件失败!"); } uint HardwareSupp; Marshal.ThrowExceptionForHR(endPointVol.QueryHardwareSupport(out HardwareSupp)); result = endPointVol; }); return(result); }
private static Win7ComInterface.IAudioMeterInformation GetAudioMeterInformation() { Win7ComInterface.IAudioMeterInformation result = null; InvokeTryCatch("Win7VolumeOperate.GetAudioMeterInformation", () => { Win7ComInterface.IMMDevice device = Device; if (device == null) { return; } const uint CLSCTX_ALL = 23u; object comMeterInfo; Guid IID_IAudioMeterInformation = typeof(Win7ComInterface.IAudioMeterInformation).GUID; Marshal.ThrowExceptionForHR(device.Activate(ref IID_IAudioMeterInformation, CLSCTX_ALL, IntPtr.Zero, out comMeterInfo)); Win7ComInterface.IAudioMeterInformation meterInfo = comMeterInfo as Win7ComInterface.IAudioMeterInformation; if (meterInfo == null) { throw new Exception("初始化 Win7以上操作系统的 音频Com IAudioMeterInformation 组件失败!"); } int HardwareSupp; Marshal.ThrowExceptionForHR(meterInfo.QueryHardwareSupport(out HardwareSupp)); result = meterInfo; }); return(result); }