use windows::{ Win32::{ Media::Audio::{ IMMNotificationClient, IMMNotificationClient_Impl, }, }, }; pub trait DeviceNotificationObserver { fn add_device(&self, device_id : &windows::core::PCWSTR); } #[windows::core::implement(IMMNotificationClient)] pub(crate) struct DeviceNotificationClient { pub observer: Box } impl IMMNotificationClient_Impl for DeviceNotificationClient { fn OnDeviceStateChanged( &self, _pwstrdeviceid: &windows::core::PCWSTR, _dwnewstate: u32, ) -> windows::core::Result<()> { Ok(()) } fn OnDeviceAdded(&self, pwstrdeviceid: &windows::core::PCWSTR) -> windows::core::Result<()> { self.observer.add_device(pwstrdeviceid); Ok(()) } fn OnDeviceRemoved(&self, _pwstrdeviceid: &windows::core::PCWSTR) -> windows::core::Result<()> { Ok(()) } fn OnDefaultDeviceChanged( &self, _flow: windows::Win32::Media::Audio::EDataFlow, _role: windows::Win32::Media::Audio::ERole, _pwstrdefaultdeviceid: &windows::core::PCWSTR, ) -> windows::core::Result<()> { Ok(()) } fn OnPropertyValueChanged( &self, _pwstrdeviceid: &windows::core::PCWSTR, _key: &windows::Win32::UI::Shell::PropertiesSystem::PROPERTYKEY, ) -> windows::core::Result<()> { Ok(()) } } impl Drop for DeviceNotificationClient { fn drop(&mut self) { println!("DNC Drop"); } }