This project is read-only.

How to use function : GetStringForReasonCode ??

Oct 14, 2010 at 9:23 AM

this is simple code : managedwifi-41381 

i add  WlanReasonNotification to WifiExample , like this

static string GetStringForSSID(Wlan.Dot11Ssid ssid)
            return Encoding.ASCII.GetString( ssid.SSID, 0, (int) ssid.SSIDLength );
        static void Main( string[] args )
            WlanClient client = new WlanClient();
            foreach ( WlanClient.WlanInterface wlanIface in client.Interfaces )
                wlanIface.WlanReasonNotification += new WlanClient.WlanInterface.WlanReasonNotificationEventHandler(wlanIface_WlanReasonNotification);

                string profileName = "RDD"; // this is also the SSID

                string key = "4227004288";
                string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"{0}{0}ESSopenWEPfalsenetworkKeyfalse{1}0\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{1}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, key);
                wlanIface.SetProfile( Wlan.WlanProfileFlags.AllUser, profileXml, true );
                wlanIface.Connect( Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName );

        static void wlanIface_WlanReasonNotification(Wlan.WlanNotificationData notifyData, Wlan.WlanReasonCode reasonCode)
            WlanClient client = new WlanClient();


when happen connection fail (ex : key mismatch...etc), program go in WlanReasonNotification event , and it will throw a exception tell me "Parameter error" in

  public string GetStringForReasonCode(Wlan.WlanReasonCode reasonCode)
   StringBuilder sb = new StringBuilder(1024); // the 1024 size here is arbitrary; the WlanReasonCodeToString docs fail to specify a recommended size
    Wlan.WlanReasonCodeToString(reasonCode, sb.Capacity, sb, IntPtr.Zero));
   return sb.ToString();

Can any one teach me how to use "GetStringForReasonCode(reasonCode);"

thanks for your help

Jul 18, 2012 at 12:31 PM


Even i wanted to know how to use GetStringForReasonCode and Catch any exception occured while connecting wifi.

Wlan.WlanReasonCode reasonCode = new Wlan.WlanReasonCode();

reasonCode = wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);

Above code reason Code will always returns Suceess even though there is exception.

If any solution please share.