none
Getting Enum from wlan api into unmanaged c# code

    Question

  • Greetings,

    I need to access WLAN_NOTIFICATION_CALLBACK function pointer Method http://msdn.microsoft.com/en-us/library/windows/desktop/ms706278(v=vs.85).aspx 

    But this requirse some enums and structs which I dont know how to create in c#. I'll got this code from http://www.pinvoke.net/default.aspx/wlanapi/WlanRegisterNotification.html into c#.

        public class NativeWifiWrapper
    		{
            /// <summary>
            /// Contains information provided when registering for notifications.
            /// </summary>
            /// <remarks>
            /// Corresponds to the native <c>WLAN_NOTIFICATION_DATA</c> type.
            /// </remarks>
            [StructLayout(LayoutKind.Sequential)]
            public struct WLAN_NOTIFICATION_DATA
            {
                /// <summary>
                /// Specifies where the notification comes from.
                /// </summary>
                /// <remarks>
                /// On Windows XP SP2, this field must be set to <see cref="WlanNotificationSource.None"/>, <see cref="WlanNotificationSource.All"/> or <see cref="WlanNotificationSource.ACM"/>.
                /// </remarks>
                public WLAN_NOTIFICATION_SOURCE notificationSource;
                /// <summary>
                /// Indicates the type of notification. The value of this field indicates what type of associated data will be present in <see cref="dataPtr"/>.
                /// </summary>
                public int notificationCode;
                /// <summary>
                /// Indicates which interface the notification is for.
                /// </summary>
                public Guid interfaceGuid;
                /// <summary>
                /// Specifies the size of <see cref="dataPtr"/>, in bytes.
                /// </summary>
                public int dataSize;
                /// <summary>
                /// Pointer to additional data needed for the notification, as indicated by <see cref="notificationCode"/>.
                /// </summary>
                public IntPtr dataPtr;
    
                /// <summary>
                /// Gets the notification code (in the correct enumeration type) according to the notification source.
                /// </summary>
                public object NotificationCode
                {
                    get
                    {
                        if (notificationSource == WLAN_NOTIFICATION_SOURCE.MSM)
                            return (WLAN_NOTIFICATION_CODE_MSM)notificationCode;
                        else if (notificationSource == WLAN_NOTIFICATION_SOURCE.ACM)
                            return (WLAN_NOTIFICATION_CODE_ACM)notificationCode;
                        else
                            return notificationCode;
                    }
    
                }
            }
    
    
    
    
            /// <summary>
            /// Contains information provided when registering for notifications.
            /// </summary>
            /// <remarks>
            /// Corresponds to the native <c>WLAN_NOTIFICATION_DATA</c> type.
            /// </remarks>
            [StructLayout(LayoutKind.Sequential)]
            public struct WLAN_NOTIFICATION_DATA
            {
                /// <summary>
                /// Specifies where the notification comes from.
                /// </summary>
                /// <remarks>
                /// On Windows XP SP2, this field must be set to <see cref="WlanNotificationSource.None"/>, <see cref="WlanNotificationSource.All"/> or <see cref="WlanNotificationSource.ACM"/>.
                /// </remarks>
                public WLAN_NOTIFICATION_SOURCE notificationSource;
                /// <summary>
                /// Indicates the type of notification. The value of this field indicates what type of associated data will be present in <see cref="dataPtr"/>.
                /// </summary>
                public int notificationCode;
                /// <summary>
                /// Indicates which interface the notification is for.
                /// </summary>
                public Guid interfaceGuid;
                /// <summary>
                /// Specifies the size of <see cref="dataPtr"/>, in bytes.
                /// </summary>
                public int dataSize;
                /// <summary>
                /// Pointer to additional data needed for the notification, as indicated by <see cref="notificationCode"/>.
                /// </summary>
                public IntPtr dataPtr;
    
                /// <summary>
                /// Gets the notification code (in the correct enumeration type) according to the notification source.
                /// </summary>
                public object NotificationCode
                {
                    get
                    {
                        if (notificationSource == WLAN_NOTIFICATION_SOURCE.MSM)
                            return (WLAN_NOTIFICATION_CODE_MSM)notificationCode;
                        else if (notificationSource == WLAN_NOTIFICATION_SOURCE.ACM)
                            return (WLAN_NOTIFICATION_CODE_ACM)notificationCode;
                        else
                            return notificationCode;
                    }
    
                }
            }
    
    
            [Flags]
            public enum WLAN_NOTIFICATION_SOURCE : uint
            {
                None = 0,
                /// <summary>
                /// All notifications, including those generated by the 802.1X module.
                /// </summary>
                All = 0X0000FFFF,
                /// <summary>
                /// Notifications generated by the auto configuration module.
                /// </summary>
                ACM = 0X00000008,
                /// <summary>
                /// Notifications generated by MSM.
                /// </summary>
                MSM = 0X00000010,
                /// <summary>
                /// Notifications generated by the security module.
                /// </summary>
                Security = 0X00000020,
                /// <summary>
                /// Notifications generated by independent hardware vendors (IHV).
                /// </summary>
                IHV = 0X00000040
            }
    
            public delegate void WLAN_NOTIFICATION_CALLBACK(ref WLAN_NOTIFICATION_DATA notificationData, IntPtr context);
    
            [DllImport("Wlanapi.dll", EntryPoint = "WlanRegisterNotification")]
            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);
    
        }

    So the enum WLAN_NOTIFICATION_CODE_MSM and WLAN_NOTIFICATION_CODE_ACM is missing which I think is this http://msdn.microsoft.com/en-us/library/windows/desktop/dd815255(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/dd815254(v=vs.85).aspx this. But I dont know how I do get this enum into C#. 

    Can anyone help me out there?

    best regards

    Thursday, August 16, 2012 5:48 PM

Answers

  • Both of the enumerations have the 1st entry as 0  as indicated by "=0".  Every other entry is sequentially incremented by one.  I not sure what type of number (8 bits, 16 bits, 32 bits) the enumeration should be so I made then shrt (16 bits).  This may not be correct.  You can use one of the following : byte, sbyte, short, ushort, int, uint, long or ulong

    public enum WLAN_NOTIFICATION_CODE_MSM : short
            { 
              wlan_notification_msm_start                           = 0,
              wlan_notification_msm_associating,
              wlan_notification_msm_associated,
              wlan_notification_msm_authenticating,
              wlan_notification_msm_connected,
              wlan_notification_msm_roaming_start,
              wlan_notification_msm_roaming_end,
              wlan_notification_msm_radio_state_change,
              wlan_notification_msm_signal_quality_change,
              wlan_notification_msm_disassociating,
              wlan_notification_msm_disconnected,
              wlan_notification_msm_peer_join,
              wlan_notification_msm_peer_leave,
              wlan_notification_msm_adapter_removal,
              wlan_notification_msm_adapter_operation_mode_change,
              wlan_notification_msm_end 
            }
            public enum WLAN_NOTIFICATION_CODE_ACM : short
            { 
              wlan_notification_acm_start                        = 0,
              wlan_notification_acm_autoconf_enabled,
              wlan_notification_acm_autoconf_disabled,
              wlan_notification_acm_background_scan_enabled,
              wlan_notification_acm_background_scan_disabled,
              wlan_notification_acm_bss_type_change,
              wlan_notification_acm_power_setting_change,
              wlan_notification_acm_scan_complete,
              wlan_notification_acm_scan_fail,
              wlan_notification_acm_connection_start,
              wlan_notification_acm_connection_complete,
              wlan_notification_acm_connection_attempt_fail,
              wlan_notification_acm_filter_list_change,
              wlan_notification_acm_interface_arrival,
              wlan_notification_acm_interface_removal,
              wlan_notification_acm_profile_change,
              wlan_notification_acm_profile_name_change,
              wlan_notification_acm_profiles_exhausted,
              wlan_notification_acm_network_not_available,
              wlan_notification_acm_network_available,
              wlan_notification_acm_disconnecting,
              wlan_notification_acm_disconnected,
              wlan_notification_acm_adhoc_network_state_change,
              wlan_notification_acm_profile_unblocked,
              wlan_notification_acm_screen_power_change,
              wlan_notification_acm_end 
            }


    jdweng

    Thursday, August 16, 2012 10:31 PM