Esempio n. 1
0
        /// <summary>
        /// Marshals a native AUDIO_VOLUME_NOTIFICATION_DATA structure to a <see cref="AudioVolumeNotificationData"/> object.
        /// </summary>
        /// <param name="ptr">A pointer to an AUDIO_VOLUME_NOTIFICATION_DATA structure.</param>
        /// <returns>The marshaled <see cref="AudioVolumeNotificationData"/> object.</returns>
        internal static AudioVolumeNotificationData MarshalFromPtr(IntPtr ptr)
        {
            AudioVolumeNotificationDataStruct data = (AudioVolumeNotificationDataStruct)Marshal.PtrToStructure(ptr, typeof(AudioVolumeNotificationDataStruct));
            IntPtr channelVolumesPtr = new IntPtr(ptr.ToInt64() + Marshal.OffsetOf <AudioVolumeNotificationDataStruct>("ChannelVolume0").ToInt64());

            // Read dynamic channel volumes array
            float[] channelVolume = new float[data.Channels];
            Marshal.Copy(channelVolumesPtr, channelVolume, 0, data.Channels);

            // Construct the complete AudioVolumeNotificationData object
            AudioVolumeNotificationData notificationData = new AudioVolumeNotificationData()
            {
                EventContext  = data.EventContext,
                Muted         = data.Muted,
                MasterVolume  = data.MasterVolume,
                Channels      = data.Channels,
                ChannelVolume = channelVolume,
            };

            return(notificationData);
        }
Esempio n. 2
0
 /// <summary>
 /// Callback method for endpoint-volume-change notifications.
 /// </summary>
 /// <param name="pNotify">Pointer to the notification data.</param>
 public void OnNotify(IntPtr pNotify)
 {
     this.callback?.Invoke(AudioVolumeNotificationData.MarshalFromPtr(pNotify));
 }