Example #1
0
        /// <summary>
        /// Creates a new instance of a Native Wifi service client.
        /// Throws Win32 errors: ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY, RPC_STATUS, ERROR_REMOTE_SESSION_LIMIT_EXCEEDED.
        /// </summary>
        public WlanClient()
        {
            int             errorCode = 0;
            OperatingSystem osInfo    = Environment.OSVersion;

            // this is winxp
            if (osInfo.Platform == PlatformID.Win32NT && osInfo.Version.Major == 5 && osInfo.Version.Minor != 0)
            {
                // wlanapi not supported in sp1 (or sp2 without fix)
                Console.WriteLine("xp sp " + osInfo.ServicePack);
                if (osInfo.ServicePack == "Service Pack 1")
                {
                    NoWifiAvailable = true;
                    return;
                }
                else if (osInfo.ServicePack == "Service Pack 2") // check if wlanapi is installed
                {
                    try
                    {
                        errorCode = WlanInterop.WlanOpenHandle(WlanInterop.WLAN_CLIENT_VERSION_XP_SP2, IntPtr.Zero, out negotiatedVersion, out clientHandle);
                    }
                    catch
                    {
                        errorCode = NO_WIFI;
                    }
                }
            }
            else
            {
                errorCode = WlanInterop.WlanOpenHandle(WlanInterop.WLAN_CLIENT_VERSION_XP_SP2, IntPtr.Zero, out negotiatedVersion, out clientHandle);
            }


            if (errorCode == NO_WIFI)
            {
                NoWifiAvailable = true;
                return;
            }
            // 1062 = no wifi
            // OK!
            WlanInterop.ThrowIfError(errorCode);

            try
            {
                // Interop callback
                wlanNotificationCallback = new WlanInterop.WlanNotificationCallbackDelegate(OnWlanNotification);

                WlanNotificationSource prevSrc;
                WlanInterop.ThrowIfError(WlanInterop.WlanRegisterNotification(clientHandle, WlanNotificationSource.All, false, wlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out prevSrc));
            }
            catch
            {
                WlanInterop.WlanCloseHandle(clientHandle, IntPtr.Zero);
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new instance of a Native Wifi service client.
        /// Throws Win32 errors: ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY, RPC_STATUS, ERROR_REMOTE_SESSION_LIMIT_EXCEEDED.
        /// </summary>
        public WlanClient()
        {
            int             errorCode = 0;
            OperatingSystem osInfo    = Environment.OSVersion;

            bool isWinXP =
                osInfo.Platform == PlatformID.Win32NT &&
                osInfo.Version.Major == 5 &&
                osInfo.Version.Minor != 0;

            if (isWinXP && osInfo.ServicePack == "Service Pack 1")             // wlanapi not supported in sp1 (or sp2 without hotfix)
            {
                errorCode = NO_WIFI;
            }
            else
            {
                // Perform exception safe init
                // It can be SP2 without hotfix which would generate exception
                try
                {
                    errorCode = WlanInterop.WlanOpenHandle(WlanInterop.WLAN_CLIENT_VERSION_XP_SP2, IntPtr.Zero, out negotiatedVersion, out clientHandle);
                }
                catch
                {
                    errorCode = NO_WIFI;
                }
            }

            if (errorCode != 0)
            {
                NoWifiAvailable = true;
                return;
            }

            // 1062 = no wifi
            // OK!
            // WlanInterop.ThrowIfError(errorCode);

            try
            {
                // Interop callback
                wlanNotificationCallback = new WlanInterop.WlanNotificationCallbackDelegate(OnWlanNotification);

                WlanNotificationSource prevSrc;
                WlanInterop.ThrowIfError(WlanInterop.WlanRegisterNotification(clientHandle, WlanNotificationSource.All, false, wlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out prevSrc));
            }
            catch
            {
                WlanInterop.WlanCloseHandle(clientHandle, IntPtr.Zero);
                throw;
            }
        }
Example #3
0
		/// <summary>
		/// Creates a new instance of a Native Wifi service client.
		/// Throws Win32 errors: ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY, RPC_STATUS, ERROR_REMOTE_SESSION_LIMIT_EXCEEDED.
		/// </summary>
		public WlanClient()
		{
			int errorCode = 0;
			OperatingSystem osInfo = Environment.OSVersion;			

			bool isWinXP = 
				osInfo.Platform == PlatformID.Win32NT && 
				osInfo.Version.Major == 5 && 
				osInfo.Version.Minor != 0;
						
			if (isWinXP && osInfo.ServicePack == "Service Pack 1") // wlanapi not supported in sp1 (or sp2 without hotfix)
			{
				errorCode = NO_WIFI;                
			}
			else
			{
				// Perform exception safe init
				// It can be SP2 without hotfix which would generate exception
				try
				{
					errorCode = WlanInterop.WlanOpenHandle(WlanInterop.WLAN_CLIENT_VERSION_XP_SP2, IntPtr.Zero, out negotiatedVersion, out clientHandle);					
				}
				catch
				{
					errorCode = NO_WIFI;
				}                
			}
			
			if (errorCode != 0)
			{
				NoWifiAvailable = true;
				return;
			}

			// 1062 = no wifi
			// OK!
			// WlanInterop.ThrowIfError(errorCode);

			try
			{
				// Interop callback
				wlanNotificationCallback = new WlanInterop.WlanNotificationCallbackDelegate(OnWlanNotification);

				WlanNotificationSource prevSrc;
				WlanInterop.ThrowIfError(WlanInterop.WlanRegisterNotification(clientHandle, WlanNotificationSource.All, false, wlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out prevSrc));
			}
			catch
			{
				WlanInterop.WlanCloseHandle(clientHandle, IntPtr.Zero);
				throw;
			}
		}