public static IDeviceTopology DeviceTopology(this MMDevice device) { var attribute = typeof(IDeviceTopology).GetCustomAttributes(typeof(GuidAttribute), true).Cast <GuidAttribute>().FirstOrDefault(); if (attribute == null) { return(null); } var pInterface = device.Activate(new Guid(attribute.Value), CLSCTX.CLSCTX_ALL, IntPtr.Zero); return(Marshal.GetObjectForIUnknown(pInterface) as IDeviceTopology); }