Esempio n. 1
0
            private void RegisterNotification()
            {
                // Storing a delegate in class field is necessary to prevent garbage collector from collecting
                // the delegate before it is called. Otherwise, CallbackOnCollectedDelegate may occur.
                _notificationCallback = new WLAN_NOTIFICATION_CALLBACK((data, context) =>
                {
                    var notificationData = Marshal.PtrToStructure <WLAN_NOTIFICATION_DATA>(data);
                    if (notificationData.NotificationSource != WLAN_NOTIFICATION_SOURCE_ACM)
                    {
                        return;
                    }

                    NotificationReceived?.Invoke(null, notificationData);
                });

                var result = WlanRegisterNotification(
                    Handle,
                    WLAN_NOTIFICATION_SOURCE_ACM,
                    false,
                    _notificationCallback,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    0);

                CheckResult(nameof(WlanRegisterNotification), result, true);
            }
Esempio n. 2
0
        private void RegisterNotification(IntPtr clientHandle, Action <WLAN_NOTIFICATION_DATA> notificationReceived)
        {
            // Storing a delegate in class field is necessary to prevent garbage collector from collecting
            // the delegate before it is called. Otherwise, CallbackOnCollectedDelegate may occur.
            _notificationCallback = new WLAN_NOTIFICATION_CALLBACK((data, context) =>
            {
                var notificationData = Marshal.PtrToStructure <WLAN_NOTIFICATION_DATA>(data);
                if (notificationData.NotificationSource != WLAN_NOTIFICATION_SOURCE_ACM)
                {
                    return;
                }

                notificationReceived?.Invoke(notificationData);
            });

            var result = WlanRegisterNotification(
                clientHandle,
                WLAN_NOTIFICATION_SOURCE_ACM,
                false,
                _notificationCallback,
                IntPtr.Zero,
                IntPtr.Zero,
                0);

            if (result != ERROR_SUCCESS)
            {
                throw new Win32Exception((int)result);
            }
        }
Esempio n. 3
0
 public static extern uint WlanRegisterNotification(
     SafeClientHandle hClientHandle,
     uint dwNotifSource,
     [MarshalAs(UnmanagedType.Bool)] bool bIgnoreDuplicate,
     WLAN_NOTIFICATION_CALLBACK funcCallback,
     IntPtr pCallbackContext,
     IntPtr pReserved,
     uint pdwPrevNotifSource);
Esempio n. 4
0
 public static extern uint WlanRegisterNotification(
     IntPtr hClientHandle,
     WLAN_NOTIFICATION_SOURCE dwNotifSource,
     bool bIgnoreDuplicate,
     WLAN_NOTIFICATION_CALLBACK funcCallback,
     IntPtr pCallbackContext,
     IntPtr pReserved,
     [Out] out WLAN_NOTIFICATION_SOURCE pdwPrevNotifSource);
Esempio n. 5
0
        private void UnregisterNotification(IntPtr clientHandle)
        {
            _notificationCallback = new WLAN_NOTIFICATION_CALLBACK((data, context) => { });

            var result = WlanRegisterNotification(
                clientHandle,
                WLAN_NOTIFICATION_SOURCE_NONE,
                false,
                _notificationCallback,
                IntPtr.Zero,
                IntPtr.Zero,
                0);
        }
Esempio n. 6
0
            private void UnregisterNotification()
            {
                _notificationCallback = new WLAN_NOTIFICATION_CALLBACK((data, context) => { });

                var result = WlanRegisterNotification(
                    Handle,
                    WLAN_NOTIFICATION_SOURCE_NONE,
                    false,
                    _notificationCallback,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    0);

                CheckResult(nameof(WlanRegisterNotification), result, true);
            }
Esempio n. 7
0
        public static void RegisterNotification(SafeClientHandle clientHandle, uint notificationSource, Action <IntPtr, IntPtr> callback)
        {
            // Storing a delegate in class field is necessary to prevent garbage collector from collecting it
            // before the delegate is called. Otherwise, CallbackOnCollectedDelegate may occur.
            _notificationCallback = new WLAN_NOTIFICATION_CALLBACK(callback);

            var result = WlanRegisterNotification(clientHandle,
                                                  notificationSource,
                                                  false,
                                                  _notificationCallback,
                                                  IntPtr.Zero,
                                                  IntPtr.Zero,
                                                  0);

            CheckResult(nameof(WlanRegisterNotification), result, true);
        }
Esempio n. 8
0
 public static extern uint WlanRegisterNotification(IntPtr hClientHandle, WLAN_NOTIFICATION_SOURCE dwNotifSource, bool bIgnoreDuplicate,
     WLAN_NOTIFICATION_CALLBACK funcCallback, IntPtr pCallbackContext, IntPtr pReserved, [Out] out WLAN_NOTIFICATION_SOURCE pdwPrevNotifSource);
		private static void RegisterNotification(IntPtr clientHandle, uint notificationSource, Action<IntPtr, IntPtr> callback)
		{
			// Storing a delegate in class field is necessary to prevent garbage collector from collecting it
			// before the delegate is called. Otherwise, CallbackOnCollectedDelegate may occur.
			_notificationCallback = new WLAN_NOTIFICATION_CALLBACK(callback);

			var result = WlanRegisterNotification(clientHandle,
				notificationSource,
				false,
				_notificationCallback,
				IntPtr.Zero,
				IntPtr.Zero,
				0);

			CheckResult(result, "WlanRegisterNotification", true);
		}
Esempio n. 10
0
		private static extern uint WlanRegisterNotification(
			IntPtr hClientHandle,
			uint dwNotifSource,
			[MarshalAs(UnmanagedType.Bool)] bool bIgnoreDuplicate,
			WLAN_NOTIFICATION_CALLBACK funcCallback,
			IntPtr pCallbackContext,
			IntPtr pReserved,
			uint pdwPrevNotifSource);