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); }
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); } }
public static extern uint WlanRegisterNotification( SafeClientHandle hClientHandle, uint dwNotifSource, [MarshalAs(UnmanagedType.Bool)] bool bIgnoreDuplicate, WLAN_NOTIFICATION_CALLBACK funcCallback, IntPtr pCallbackContext, IntPtr pReserved, uint pdwPrevNotifSource);
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 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); }
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); }
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); }
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); }
private static extern uint WlanRegisterNotification( IntPtr hClientHandle, uint dwNotifSource, [MarshalAs(UnmanagedType.Bool)] bool bIgnoreDuplicate, WLAN_NOTIFICATION_CALLBACK funcCallback, IntPtr pCallbackContext, IntPtr pReserved, uint pdwPrevNotifSource);