Jump to content

Multi dimentional array help


Recommended Posts

Hi i am writing a wireless manager and i kind of got stuck i am using "Native Wifi Functions" i am kinda new to this so i checked the examples and what not it came with also checked forums not alot of support on it but im looking to list the wireless networks in a list view in the example it uses _arraydisplay witch makes it's own GUI so i cannot use it i am looking to only pick up the SSID and the Signil strength of the wireless network the code i am using is underneath um other then that please dont spam post making fun of the code as i said i just started ;)

The wireless manager

#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <GuiListView.au3>
#include "Native_Wifi_Func_V3_1b.au3"

wireless()


Func wireless()
    Local $msg

    GUICreate("Wireless demo",300,250)
    GUISetState(@SW_SHOW) 
    GUICtrlCreatePic(@scriptdir & "\Black_VRD_Logo.gif", 25, 0, 250, 50)
    Global $listView = GuiCtrlCreateListView("Wireless Network|Signel", 120, 50, 177, 200)

        $refresh = GUICtrlCreateButton("Refresh", 10, 80, 100)
        GUICtrlCreateButton("Connect", 10, 110, 100)
        GUICtrlCreateButton("Advanced", 10, 140, 100)
        GUICtrlCreateButton("Options" , 10 , 170, 100)
    
        Do
        $msg = GUIGetMsg()
        if $msg = $refresh Then
            _GUICtrlListView_DeleteAllItems($listView)
            $Start = _Wlan_StartSession()
            _Wlan_Scan(-1, -1)
            $Nets = _Wlan_GetAvailableNetworkList(-1, -1, 1)
            ;Want to put it in the list view with the SSID and the Signel here
            GuiCtrlcreatelistviewitem($Nets[0][0],$listView) 
            sleep(200)
        EndIf
      
        $msg = GUIGetMsg()

    Until $msg = $GUI_EVENT_CLOSE
EndFunc


Func OnAutoItExit()
    _Wlan_EndSession(-1) ;Calls CloseHandle and closes the dll
EndFunc

Here is the Native wifi include i am using

#cs
13/08/2009 - Version 3.1b
-----------------------------------------------------------------
----------------------NATIVE WIFI FUNCTIONS----------------------
--------------------------For WinXP SP3--------------------------
----------------------------by MattyD----------------------------
-----------------------------------------------------------------
#CE
#include-once

Global $a_iCall, $ErrorMessage, $WLANAPIDLL = DllOpen("wlanapi.dll"), $GLOBAL_hClientHandle = 1, $GLOBAL_pGUID, $PTR_INFOLIST = 0, $CallbackDisconnectCount = 0, $CallbackConnectCount = 0,$CallbackSSID

Global _ ;Enumerations
$DOT11_AUTH_ALGORITHM                       = 0, _
    $DOT11_AUTH_ALGO_80211_OPEN                 = 1, _
    $DOT11_AUTH_ALGO_80211_SHARED_KEY           = 2, _
    $DOT11_AUTH_ALGO_WPA                        = 3, _
    $DOT11_AUTH_ALGO_WPA_PSK                    = 4, _
    $DOT11_AUTH_ALGO_WPA_NONE                   = 5, _
    $DOT11_AUTH_ALGO_RSNA                       = 6, _
    $DOT11_AUTH_ALGO_RSNA_PSK                   = 7, _
$DOT11_BSS_TYPE                             = 1, _
    $dot11_BSS_type_infrastructure              = 1, _
    $dot11_BSS_type_independent                 = 2, _
    $dot11_BSS_type_any                         = 3, _
$DOT11_CIPHER_ALGORITHM                     = 2, _
    $DOT11_CIPHER_ALGO_NONE                     = 0x00, _
    $DOT11_CIPHER_ALGO_WEP40                    = 0x01, _
    $DOT11_CIPHER_ALGO_TKIP                     = 0x02, _
    $DOT11_CIPHER_ALGO_CCMP                     = 0x04, _
    $DOT11_CIPHER_ALGO_WEP104                   = 0x05, _
    $DOT11_CIPHER_ALGO_WEP                      = 0x101, _
$WLAN_CONNECTION_MODE                       = 3, _ 
    $wlan_connection_mode_profile               = 0, _
$WLAN_INTERFACE_STATE                       = 4, _
    $wlan_interface_state_connected             = 1, _
    $wlan_interface_state_disconnected          = 4, _
    $wlan_interface_state_authenticating        = 7, _
$WLAN_INTF_OPCODE                           = 5, _
    $wlan_intf_opcode_autoconf_enabled          = 1, _
    $wlan_intf_opcode_bss_type                  = 5, _
    $wlan_intf_opcode_interface_state           = 6, _
    $wlan_intf_opcode_current_connection        = 7, _
$WLAN_OPCODE_VALUE_TYPE                     = 6, _
    $wlan_opcode_value_type_query_only          = 0, _
    $wlan_opcode_value_type_set_by_group_policy = 1, _
    $wlan_opcode_value_type_set_by_user         = 2, _
    $wlan_opcode_value_type_invalid             = 3

Global _ ;Struct Strings
$GUID_STRUCT                        = "ulong GUIDFIRST; ushort GUIDSECOND; ushort GUIDTHIRD; ubyte GUIDFOURTH[8]", _
$DOT11_MAC_ADDRESS                  = "byte DOT11MACADDRESS[6]", _
$DOT11_SSID                         = "ulong uSSIDLength; char ucSSID[32]", _
$WLAN_ASSOCIATION_ATTRIBUTES        = $DOT11_SSID & "; dword DOT11BSSTYPE; " & $DOT11_MAC_ADDRESS & "; dword DOT11PHYTYPE; ulong uDot11PhyIndex; ulong WLANSIGNALQUALITY; ulong ulRxRate; ulong ulTxRate", _
$WLAN_AVAILABLE_NETWORK             = "wchar strProfileName[256]; " & $DOT11_SSID & "; dword DOT11BSSTYPE; ulong uNumberOfBssids; int bNetworkConnectable; dword WLANREASONCODE; ulong uNumberOfPhyTypes; dword DOT11PHYTYPE[8]; int bMorePhyTypes; ulong WLANSIGNALQUALITY; int bSecurityEnabled; dword DOT11AUTHALGORITHM; dword DOT11CIPHERALGORITHM; dword dwFlags; dword dwReserved", _
$WLAN_AVAILABLE_NETWORK_LIST        = "dword dwNumberOfItems; dword dwIndex", _
$WLAN_SECURITY_ATTRIBUTES           = "int bSecurityEnabled; int bOneXEnabled; dword DOT11AUTHALGORITHM; dword DOT11CIPHERALGORITHM", _
$WLAN_CONNECTION_ATTRIBUTES         = "dword WLANINTERFACESTATE; dword WLANCONNECTIONMODE; wchar strProfileName[256]; " & $WLAN_ASSOCIATION_ATTRIBUTES & "; " & $WLAN_SECURITY_ATTRIBUTES, _
$WLAN_CONNECTION_NOTIFICATION_DATA  = "dword WLANCONNECTIONMODE; wchar strProfileName[256]; " & $DOT11_SSID & "; dword DOT11BSSTYPE; int bSecurityEnabled; dword WLANREASONCODE; wchar strProfileXml[4096]", _
$WLAN_CONNECTION_PARAMETERS         = "dword WLANCONNECTIONMODE; ptr strProfile; ptr PDOT11SSID; ptr PDOT11BSSIDLIST; dword DOT11BSSTYPE; dword dwFlags", _
$WLAN_INTERFACE_INFO                = $GUID_STRUCT & "; wchar strInterfaceDescription[256]; dword WLANINTERFACESTATE", _
$WLAN_INTERFACE_INFO_LIST           = "dword dwNumberOfItems; dword dwIndex", _
$WLAN_NOTIFICATION_DATA             = "dword NotificationSource; dword NotificationCode; " & $GUID_STRUCT & "; dword dwDataSize; ptr pData", _
$WLAN_PROFILE_INFO                  = "wchar strProfileName[256]; dword dwFlags", _
$WLAN_PROFILE_INFO_LIST             = "dword dwNumberOfItems; dword dwIndex"

Func _Wlan_OpenHandle()
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanOpenHandle", "dword", 1, "ptr", 0, "dword*", 0, "hwnd*", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] == 0 Then
            Return $a_iCall[4]
        Else
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

Func _Wlan_CloseHandle($hClientHandle)
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanCloseHandle", "ptr", $hClientHandle, "ptr", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

Func _Wlan_EnumInterfaces($hClientHandle)
    Local $pInfoList, $INFO_LIST, $NumberOfItems, $StructString, $index
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    
    If $PTR_INFOLIST <> 0 Then _Wlan_FreeMemory($PTR_INFOLIST)
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanEnumInterfaces", "hwnd", $hClientHandle , "ptr", 0, "ptr*", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        Else
            $pInfoList = $a_iCall[3]
            $PTR_INFOLIST = $a_iCall[3]
            $INFO_LIST = DllStructCreate($WLAN_INTERFACE_INFO_LIST, $pInfoList)
            $NumberOfItems = DllStructGetData($INFO_LIST, "dwNumberOfItems")
            
            If $NumberOfItems = 0 Then
                SetError(2)
                Return 0
            Else
                $StructString = _Wlan_BuildListStructString($WLAN_INTERFACE_INFO_LIST, $WLAN_INTERFACE_INFO, $NumberOfItems)
                $INFO_LIST = DllStructCreate($StructString, $pInfoList)
                
                Dim $InterfaceArray[$NumberOfItems][3]
                
                For $i = 0 To $NumberOfItems - 1
                    $InterfaceArray[$i][0] = $pInfoList + $i * 532 + 8
                    $InterfaceArray[$i][1] = StringRegExpReplace(DllStructGetData($INFO_LIST, "strInterfaceDescription" & $index), " - Packet Scheduler Miniport", "")
                    $InterfaceArray[$i][2] = DllStructGetData($INFO_LIST, "WLANINTERFACESTATE" & $index)
                    If $InterfaceArray[$i][2] = $wlan_interface_state_connected Then $InterfaceArray[$i][2] = "Connected"
                    If $InterfaceArray[$i][2] = $wlan_interface_state_disconnected Then $InterfaceArray[$i][2] = "Disconnected"
                    If $InterfaceArray[$i][2] = $wlan_interface_state_authenticating Then $InterfaceArray[$i][2] = "Authenticating"
                    $index += 1
                Next
                
               Return($InterfaceArray)
            EndIf
        EndIf
    EndIf
EndFunc

Func _Wlan_Scan($hClientHandle, $pGUID)
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanScan", "hwnd", $hClientHandle, "ptr", $pGUID, "ptr", 0, "ptr", 0, "ptr", 0)
        
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

Func _Wlan_GetAvailableNetworkList($hClientHandle, $pGUID, $dwFlag)
    Local $NETWORK_LIST, $index, $pAvailableNetworkList, $NumberOfItems, $StructString, $ArrayDuplicateCount = 0, $ArrayTransferCount = 0
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanGetAvailableNetworkList", "hwnd", $hClientHandle, "ptr", $pGUID, "dword", $dwFlag, "ptr", 0, "ptr*", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        Else    
            $pAvailableNetworkList = $a_iCall[5]
            
            Global $NETWORK_LIST = DllStructCreate($WLAN_AVAILABLE_NETWORK_LIST, $pAvailableNetworkList)
            Global $NumberOfItems = DllStructGetData($NETWORK_LIST, "dwNumberOfItems")
            
            If $NumberOfItems = 0 Then
                SetError(2)
                Return 0
            Else
                $StructString = _Wlan_BuildListStructString($WLAN_AVAILABLE_NETWORK_LIST, $WLAN_AVAILABLE_NETWORK, $NumberOfItems)
                
                Global $NETWORK_LIST = DllStructCreate($StructString, $pAvailableNetworkList)
                
                Dim $AvailableNetworkArray[$NumberOfItems][8]
                
                For $i = 0 To $NumberOfItems - 1
                    $AvailableNetworkArray[$i][0] = DllStructGetData($NETWORK_LIST, "ucSSID" & $index)
                    $AvailableNetworkArray[$i][1] = DllStructGetData($NETWORK_LIST, "DOT11BSSTYPE" & $index)
                    $AvailableNetworkArray[$i][2] = DllStructGetData($NETWORK_LIST, "bNetworkConnectable" & $index)
                    $AvailableNetworkArray[$i][3] = DllStructGetData($NETWORK_LIST, "WLANSIGNALQUALITY" & $index)
                    $AvailableNetworkArray[$i][4] = DllStructGetData($NETWORK_LIST, "DOT11AUTHALGORITHM" & $index)
                    $AvailableNetworkArray[$i][5] = DllStructGetData($NETWORK_LIST, "DOT11CIPHERALGORITHM" & $index)
                    $AvailableNetworkArray[$i][6] = DllStructGetData($NETWORK_LIST, "dwFlags" & $index)
                    $AvailableNetworkArray[$i][7] = DllStructGetData($NETWORK_LIST, "WLANREASONCODE" & $index)
                    $index += 1
                    
                    If $AvailableNetworkArray[$i][1] == $dot11_BSS_type_infrastructure      Then $AvailableNetworkArray[$i][1] = "Infrastructure"
                    If $AvailableNetworkArray[$i][1] == $dot11_BSS_type_independent         Then $AvailableNetworkArray[$i][1] = "Ad Hoc"
                    If $AvailableNetworkArray[$i][2] == 1                                   Then $AvailableNetworkArray[$i][2] = "Connectable"
                    If $AvailableNetworkArray[$i][2] == 0                                   Then $AvailableNetworkArray[$i][2] = "Not Connectable"
                    If $AvailableNetworkArray[$i][4] == $DOT11_AUTH_ALGO_80211_OPEN         Then $AvailableNetworkArray[$i][4] = "Open"
                    If $AvailableNetworkArray[$i][4] == $DOT11_AUTH_ALGO_80211_SHARED_KEY   Then $AvailableNetworkArray[$i][4] = "Shared Key"
                    If $AvailableNetworkArray[$i][4] == $DOT11_AUTH_ALGO_WPA                Then $AvailableNetworkArray[$i][4] = "WPA"
                    If $AvailableNetworkArray[$i][4] == $DOT11_AUTH_ALGO_WPA_PSK            Then $AvailableNetworkArray[$i][4] = "WPA-PSK"
                    If $AvailableNetworkArray[$i][4] == $DOT11_AUTH_ALGO_RSNA               Then $AvailableNetworkArray[$i][4] = "WPA2"
                    If $AvailableNetworkArray[$i][4] == $DOT11_AUTH_ALGO_RSNA_PSK           Then $AvailableNetworkArray[$i][4] = "WPA2-PSK"
                    If $AvailableNetworkArray[$i][5] == $DOT11_CIPHER_ALGO_NONE             Then $AvailableNetworkArray[$i][5] = "Unencrypted"
                    If $AvailableNetworkArray[$i][5] == $DOT11_CIPHER_ALGO_WEP40            Then $AvailableNetworkArray[$i][5] = "WEP-64"
                    If $AvailableNetworkArray[$i][5] == $DOT11_CIPHER_ALGO_TKIP             Then $AvailableNetworkArray[$i][5] = "TKIP"
                    If $AvailableNetworkArray[$i][5] == $DOT11_CIPHER_ALGO_CCMP             Then $AvailableNetworkArray[$i][5] = "AES"
                    If $AvailableNetworkArray[$i][5] == $DOT11_CIPHER_ALGO_WEP104           Then $AvailableNetworkArray[$i][5] = "WEP-128"
                    If $AvailableNetworkArray[$i][5] == $DOT11_CIPHER_ALGO_WEP              Then $AvailableNetworkArray[$i][5] = "WEP"
                    If $AvailableNetworkArray[$i][6] == 3                                   Then $AvailableNetworkArray[$i][6] = "Connected"
                    If $AvailableNetworkArray[$i][6] == 2                                   Then $AvailableNetworkArray[$i][6] = "Profile"
                    If $AvailableNetworkArray[$i][6] == 0                                   Then $AvailableNetworkArray[$i][6] = "No Profile"
                    If $AvailableNetworkArray[$i][7] <> ""                                  Then $AvailableNetworkArray[$i][7] = _Wlan_ReasonCodeToString($AvailableNetworkArray[$i][7])
                Next

                _Wlan_FreeMemory($pAvailableNetworkList)

                For $i = 0 To $NumberOfItems - 1
                    For $j = $i + 1 To $NumberOfItems - 1
                        If $AvailableNetworkArray[$i][0] == "" And $AvailableNetworkArray[$i][1] == "Ad Hoc" Then 
                            $AvailableNetworkArray[$i][0] = "@"
                            $ArrayDuplicateCount += 1
                        EndIf
                        If $AvailableNetworkArray[$i][0] == $AvailableNetworkArray[$j][0] And $AvailableNetworkArray[$i][1] == $AvailableNetworkArray[$j][1] Then
                            If $AvailableNetworkArray[$i][6] == "No Profile" And $AvailableNetworkArray[$i][0] <> "@" Then
                                $AvailableNetworkArray[$i][0] = "@"
                                $ArrayDuplicateCount += 1
                            ElseIf $AvailableNetworkArray[$j][6] == "No Profile" And $AvailableNetworkArray[$i][0] <> "@" Then
                                $AvailableNetworkArray[$j][0] = "@"
                                $ArrayDuplicateCount += 1
                            EndIf
                        EndIf
                    Next
                Next
                
                Dim $AvailableNetworkArrayDuplicate[$NumberOfItems - $ArrayDuplicateCount][8]
                
                For $i = 0 To $NumberOfItems - 1
                    If $AvailableNetworkArray[$i][0] <> "@" then 
                        For $j = 0 To 7
                            $AvailableNetworkArrayDuplicate[$ArrayTransferCount][$j] = $AvailableNetworkArray[$i][$j]
                        Next
                        $ArrayTransferCount += 1
                    EndIf
                Next
                
                $AvailableNetworkArray = $AvailableNetworkArrayDuplicate
                Return $AvailableNetworkArray
            EndIf
        EndIf
    EndIf
EndFunc

Func _Wlan_Connect($hClientHandle, $pGUID, $SSID)
    Local $strProfile, $ConnectionParameters
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $strProfile = DllStructCreate("wchar strProfile[256]")
    DllStructSetData($strProfile, "strProfile", $SSID)

    $ConnectionParameters = DllStructCreate($WLAN_CONNECTION_PARAMETERS)
    DllStructSetData($ConnectionParameters, "strProfile", DllStructGetPtr($strProfile))
    DllStructSetData($ConnectionParameters, "DOT11BSSTYPE", 1)
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanConnect", "hwnd", $hClientHandle, "ptr", $pGUID, "ptr", DllStructGetPtr($ConnectionParameters), "ptr", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

Func _Wlan_Disconnect($hClientHandle, $pGUID)
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanDisconnect", "hwnd", $hClientHandle, "ptr", $pGUID, "ptr", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

Func _Wlan_ConnectWait($hClientHandle, $pGUID, $SSID, $Timeout)
    Local $strProfile, $ConnectionParameters, $Timer
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $CallbackConnectCount = 0
    
    $strProfile = DllStructCreate("wchar strProfile[256]")
    DllStructSetData($strProfile, "strProfile", $SSID)

    $ConnectionParameters = DllStructCreate($WLAN_CONNECTION_PARAMETERS)
    DllStructSetData($ConnectionParameters, "strProfile", DllStructGetPtr($strProfile))
    DllStructSetData($ConnectionParameters, "DOT11BSSTYPE", 1)
    
    _Wlan_RegisterNotification($hClientHandle, 1)
    
    $Timer = TimerInit()
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanConnect", "hwnd", $hClientHandle, "ptr", $pGUID, "ptr", DllStructGetPtr($ConnectionParameters), "ptr", 0)
    If @error <> 0 Then
        _Wlan_RegisterNotification($hClientHandle, 0)
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            _Wlan_RegisterNotification($hClientHandle, 0)
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
        
        While 1
            Select
                Case TimerDiff($Timer) > 1000 * $Timeout
                    $Timeout = "Timeout"
                    ExitLoop
                Case $CallbackConnectCount = 3
                    ExitLoop
            EndSelect
            Sleep(500)
        WEnd

    _Wlan_RegisterNotification($hClientHandle, 0)
    
    If $Timeout = "Timeout" Then SetError(5)
    Return $CallbackSSID
    EndIf
EndFunc

Func _Wlan_DisconnectWait($hClientHandle, $pGUID, $Timeout)
    Local $Timer
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $CallbackDisconnectCount = 0
    
    _Wlan_RegisterNotification($hClientHandle, 1)
    
    $Timer = TimerInit()

    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanDisconnect", "hwnd", $hClientHandle, "ptr", $pGUID, "ptr", 0)
    
    If @error <> 0 Then
        _Wlan_RegisterNotification($hClientHandle, 0)
        SetError(4)
        Return 0
    Else
        
        If $a_iCall[0] <> 0 Then
            _Wlan_RegisterNotification($hClientHandle, 0)
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf

        While 1
            Select
                Case TimerDiff($Timer) > 1000 * $Timeout
                    $Timeout = "Timeout"
                    ExitLoop
                Case $CallbackDisconnectCount = 1
                    ExitLoop
            EndSelect
            Sleep(500)
        WEnd
    
    _Wlan_RegisterNotification($hClientHandle, 0)
    
    If $Timeout = "Timeout" Then SetError(5)
    EndIf
EndFunc

Func _Wlan_GetProfileList($hClientHandle, $pGUID)
    Local $pProfileList, $PROFILE_LIST, $NumberOfItems, $StructString, $index
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanGetProfileList", "hwnd", $hClientHandle, "ptr", $pGUID, "ptr", 0, "ptr*", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else    
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        Else    
            $pProfileList = $a_iCall[4]
            $PROFILE_LIST = DllStructCreate($WLAN_PROFILE_INFO_LIST, $pProfileList)
            $NumberOfItems = DllStructGetData($PROFILE_LIST, "dwNumberOfItems")
            
            If $NumberOfItems = 0 Then
                SetError(2)
                Return 0
            Else
                $StructString = _Wlan_BuildListStructString($WLAN_PROFILE_INFO_LIST, $WLAN_PROFILE_INFO, $NumberOfItems)
                $PROFILE_LIST = DllStructCreate($StructString, $pProfileList)
                
                Dim $ProfileArray[$NumberOfItems]
                
                For $i = 0 To $NumberOfItems - 1
                    $ProfileArray[$i] = DllStructGetData($PROFILE_LIST, "strProfileName" & $index)
                    $index += 1
                Next
                
                _Wlan_FreeMemory($pProfileList)
                
                Return $ProfileArray
            EndIf
        EndIf
    EndIf
EndFunc

Func _Wlan_SetProfileList($hClientHandle, $pGUID, $aProfileNames)
    Local $StructString = "ptr", $NumberOfItems = UBound($aProfileNames)
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    If $NumberOfItems = 0 Then
        SetError(2)
        Return(0)
    EndIf
    
    For $i = 1 To $NumberOfItems - 1
        $StructString = $StructString & ";ptr"
    Next
    For $i = 0 To $NumberOfItems - 1
        $StructString = $StructString & ";wchar[32]"
    Next
    
    $PROFILE_STRUCT = DllStructCreate($StructString)
    
    For $i = 0 To $NumberOfItems - 1
        DllStructSetData($PROFILE_STRUCT, $i + 1, DllStructGetPtr($PROFILE_STRUCT) + ($NumberOfItems * 4) + ($i * 64))
        DllStructSetData($PROFILE_STRUCT, $NumberOfItems + $i + 1, $aProfileNames[$i])
    Next
        
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanSetProfileList", "hwnd", $hClientHandle, "ptr", $pGUID, "dword", $NumberOfItems, "ptr", DllStructGetPtr($PROFILE_STRUCT), "ptr", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

Func _Wlan_GetProfile($hClientHandle, $pGUID, $SSID)
    Local $ProfileAttributes, $ProfileAttributes2, $SREString = "("
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanGetProfile", "hwnd", $hClientHandle, "ptr", $pGUID, "wstr", $SSID,"ptr", 0, "wstr*", 0, "ptr*", 0, "ptr*", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        Else
            $ProfileAttributes = StringSplit("<name>|<connectionType>|<connectionMode>|<authentication>|<encryption>|<useOneX>|<keyType>|<keyMaterial>|<keyIndex>", "|")
            For $i = 1 To UBound($ProfileAttributes) - 1
                If StringRegExp($a_iCall[5], $ProfileAttributes[$i]) == 1 Then $SREString = $SREString & $ProfileAttributes[$i] & "[^<]{0,256})[^@]{0,256}("
            Next
            $SREString = $SREString & ")"
            
            $ProfileAttributes2 = StringRegExp($a_iCall[5], $SREString, 1)
            Dim $Profile[9]
            For $i = 1 To Ubound($ProfileAttributes) - 1
                For $j = 0 To Ubound($ProfileAttributes2) - 2
                    If StringRegExp($ProfileAttributes2[$j], $ProfileAttributes[$i]) == 1 Then _
                    $Profile[$i - 1] = StringRegExpReplace($ProfileAttributes2[$j], $ProfileAttributes[$i], "")
                Next
                If String($Profile[$i - 1]) == "ESS"        Then $Profile[$i - 1] = "Infrastructure"
                If String($Profile[$i - 1]) == "IBSS"       Then $Profile[$i - 1] = "Ad Hoc"
                If String($Profile[$i - 1]) == "auto"       Then $Profile[$i - 1] = "Automatic"
                If String($Profile[$i - 1]) == "manual"     Then $Profile[$i - 1] = "Manual"
                If String($Profile[$i - 1]) == "open"       Then $Profile[$i - 1] = "Open"
                If String($Profile[$i - 1]) == "shared"     Then $Profile[$i - 1] = "Shared Key"
                If String($Profile[$i - 1]) == "WPAPSK"     Then $Profile[$i - 1] = "WPA-PSK"
                If String($Profile[$i - 1]) == "WPA2PSK"    Then $Profile[$i - 1] = "WPA2-PSK"
                If String($Profile[$i - 1]) == "none"       Then $Profile[$i - 1] = "Unencrypted"
                If String($Profile[$i - 1]) == "true"       Then $Profile[$i - 1] = "802.1x Enabled"
                If String($Profile[$i - 1]) == "false"      Then $Profile[$i - 1] = "802.1x Disabled"
                If String($Profile[$i - 1]) == "networkKey" Then $Profile[$i - 1] = "Network Key"
                If String($Profile[$i - 1]) == "passPhrase" Then $Profile[$i - 1] = "Pass Phrase"
            Next
            If String($Profile[2]) == "" And String($Profile[1]) <> "" Then $Profile[2] = "Automatic"
            If String($Profile[6]) == "" Then $Profile[6] = "No Key Material"
            If String($Profile[7]) == "" Then $Profile[7] = "No Key Material"
            If String($Profile[8]) <> "" Then $Profile[8] += 1
            If String($Profile[8]) == "" Then $Profile[8] = "No Key Index"
            Return $Profile
        EndIf
    EndIf
EndFunc

Func _Wlan_SetProfile($hClientHandle, $pGUID, $Profile)
    Local $XMLElements, $XMLProfile = '<?xml version="1.0"?>' & @CRLF, $XMLStack[1] = [-1]
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    If Ubound($Profile) <> 9 Then
        SetError(3)
        Return 0
    Else
        $XMLElements = StringSplit("WLANProfile+|name|SSIDConfig+|SSID+|name|-|-|connectionType|connectionMode|MSM+|security+|" & _
        "authEncryption+|authentication|encryption|useOneX|-|sharedKey+|keyType|protected|keyMaterial|-|keyIndex|" & _
        "OneX+|EAPConfig+|EapHostConfig+|EapMethod+|Type|VendorId|VendorType|AuthorId|-|ConfigBlob|-|-|-|-|-|-", "|")
        
        For $i = 1 To UBound($XMLElements) - 1
            If StringInStr($XMLElements[$i], "+") <> 0 Then
                $XMLProfile = $XMLProfile & "<" & StringReplace($XMLElements[$i], "+", "") & ">" & @CRLF
                Redim $XMLStack[Ubound($XMLStack) + 1]
                $XMLStack[Ubound($XMLStack) - 1] = StringReplace($XMLElements[$i], "+", "")
                $XMLStack[0] += 1
            ElseIf $XMLElements[$i] == "-" Then
                $XMLProfile = $XMLProfile & "</" & $XMLStack[Ubound($XMLStack) - 1] & ">" & @CRLF
                Redim $XMLStack[Ubound($XMLStack) - 1]
            Else
                $XMLProfile = $XMLProfile & "<" & $XMLElements[$i] & "></" & $XMLElements[$i] & ">" & @CRLF
            EndIf
            If $i < UBound($XMLElements) - 1 And $XMLElements[$i + 1] == "-" Then $XMLStack[0] -= 1
            For $j = 0 To $XMLStack[0]
                $XMLProfile = $XMLProfile & "   "
            Next
        Next
        
        If $Profile[1] == "Infrastructure"  Then $Profile[1] = "ESS"
        If $Profile[1] == "Ad Hoc"          Then $Profile[1] = "IBSS"
        If $Profile[2] == "Automatic"       Then $Profile[2] = "auto"
        If $Profile[2] == "Manual"          Then $Profile[2] = "manual"
        If $Profile[3] == "Open"            Then $Profile[3] = "open"
        If $Profile[3] == "Shared Key"      Then $Profile[3] = "shared"
        If $Profile[3] == "WPA-PSK"         Then $Profile[3] = "WPAPSK"
        If $Profile[3] == "WPA2-PSK"        Then $Profile[3] = "WPA2PSK"
        If $Profile[4] == "Unencrypted"     Then $Profile[4] = "none"
        If $Profile[6] == "Network Key"     Then $Profile[6] = "networkKey"
        If $Profile[6] == "Pass Phrase"     Then $Profile[6] = "passPhrase"
        If $Profile[6] == "No Key Material" Then $Profile[6] = ""
        If $Profile[7] == "No Key Material" Then $Profile[7] = ""
        If $Profile[8] <> "No Key Index"    Then $Profile[8] -= 1
        If $Profile[8] == "No Key Index"    Then $Profile[8] = ""

        If $Profile[5] == "802.1x Enabled" Then
            $Profile[5] = "true"
            $XMLProfile = StringRegExpReplace($XMLProfile, "[[:space:]]{0,8}<sharedKey>[^@]{0,200}</keyIndex>", "")
        ElseIf $Profile[5] == "802.1x Disabled" Then 
            $Profile[5] = "false"
            $XMLProfile = StringRegExpReplace($XMLProfile, "[[:space:]]{0,8}<OneX>[^@]{0,300}</OneX>", "")
        EndIf
        If $Profile[3] == "open" And $Profile[4] == "none" Then $XMLProfile = StringRegExpReplace($XMLProfile, "[[:space:]]{0,8}<sharedKey>[^@]{0,200}</sharedKey>", "")
        If StringIsInt($Profile[8]) == 0 Then $XMLProfile = StringRegExpReplace($XMLProfile, "[[:space:]]{0,8}<keyIndex></keyIndex>", "")
    
        $XMLProfile = StringRegExpReplace($XMLProfile, '<WLANProfile>', '<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">')
        $XMLProfile = StringRegExpReplace($XMLProfile, "<name>", "<name>" & $Profile[0])
        $XMLProfile = StringRegExpReplace($XMLProfile, "<connectionType>", "\0" & $Profile[1])
        $XMLProfile = StringRegExpReplace($XMLProfile, "<connectionMode>", "\0" & $Profile[2])
        $XMLProfile = StringRegExpReplace($XMLProfile, "<authentication>", "\0" & $Profile[3])
        $XMLProfile = StringRegExpReplace($XMLProfile, "<encryption>", "\0" & $Profile[4])
        $XMLProfile = StringRegExpReplace($XMLProfile, "<useOneX>", "\0" & $Profile[5])
        $XMLProfile = StringRegExpReplace($XMLProfile, "<keyType>", "\0" & $Profile[6])
        $XMLProfile = StringRegExpReplace($XMLProfile, "<protected>", "\0false")
        $XMLProfile = StringRegExpReplace($XMLProfile, "<keyMaterial>", "<keyMaterial>" & $Profile[7])
        $XMLProfile = StringRegExpReplace($XMLProfile, "<keyIndex>", "<keyIndex>" & $Profile[8])
        $XMLProfile = StringRegExpReplace($XMLProfile, "<OneX>", '<OneX xmlns="http://www.microsoft.com/networking/OneX/v1">')
        $XMLProfile = StringRegExpReplace($XMLProfile, "<EapHostConfig>", '<EapHostConfig xmlns="http://www.microsoft.com/provisioning/EapHostConfig">')
        $XMLProfile = StringRegExpReplace($XMLProfile, "<Type>", '<Type xmlns="http://www.microsoft.com/provisioning/EapCommon">13')
        $XMLProfile = StringRegExpReplace($XMLProfile, "<VendorId>", '<VendorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0')
        $XMLProfile = StringRegExpReplace($XMLProfile, "<VendorType>", '<VendorType xmlns="http://www.microsoft.com/provisioning/EapCommon">0')
        $XMLProfile = StringRegExpReplace($XMLProfile, "<AuthorId>", '<AuthorId xmlns="http://www.microsoft.com/provisioning/EapCommon">0')
        $XMLProfile = StringRegExpReplace($XMLProfile, "<ConfigBlob>", "<ConfigBlob>00000000280000000500000000000000000000000000000000000000000000000000000000000000")
        
        $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanSetProfile", "hwnd", $hClientHandle, "ptr", $pGUID, "dword", 0, "wstr", $XMLProfile, "ptr", 0, "int", 1, "ptr", 0, "dword*", 0)
        
        If @error <> 0 Then
            SetError(4)
            Return 0
        Else        
            If $a_iCall[0] <> 0 Then
                $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
                SetError(1, $a_iCall[0])
                Return $ErrorMessage
            EndIf
        EndIf
    EndIf
EndFunc

Func _Wlan_DeleteProfile($hClientHandle, $pGUID, $SSID) 
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanDeleteProfile", "hwnd", $hClientHandle, "ptr", $pGUID, "wstr", $SSID, "ptr", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

Func _Wlan_SetProfilePosition($hClientHandle, $pGUID, $SSID, $dwPosition)
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanSetProfilePosition", "hwnd", $hClientHandle, "ptr", $pGUID, "wstr", $SSID, "dword", $dwPosition, "ptr", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

Func _Wlan_QueryInterface($hClientHandle, $pGUID, $dwFlag)
    Local $pData, $Output, $AutoConfigState, $BssType, $DOT11BSSTYPE, $ConnectionAttributes
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
        
    If $dwFlag == 0 Then 
        $dwFlag = $wlan_intf_opcode_autoconf_enabled
    ElseIf $dwFlag == 1 Then 
        $dwFlag = $wlan_intf_opcode_bss_type
    ElseIf $dwFlag == 2 Then 
        $dwFlag = $wlan_intf_opcode_interface_state
    ElseIf $dwFlag == 3 Then 
        $dwFlag = $wlan_intf_opcode_current_connection
    EndIf
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanQueryInterface", "hwnd", $hClientHandle, "ptr", $pGUID, "dword", $dwFlag, "ptr", 0, "dword*", 0, "ptr*", 0, "dword*", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        Else        
            $pData = $a_iCall[6]
            
            If $dwFlag == $wlan_intf_opcode_autoconf_enabled Then
                $AutoConfigState = DllStructCreate("int bool", $pData)
                $Output = DllStructGetData($AutoConfigState, "bool")
                If $Output == 1 Then $Output = "Auto Config Enabled"
                If $Output == 0 Then $Output = "Auto Config Disabled"
            ElseIf $dwFlag == $wlan_intf_opcode_bss_type Then
                $BssType = DllStructCreate("dword DOT11BSSTYPE", $pData)
                $DOT11BSSTYPE = DllStructGetData($BssType, "DOT11BSSTYPE")
                If $DOT11BSSTYPE == $dot11_BSS_type_infrastructure  Then $Output = "Infrastructure Only"
                If $DOT11BSSTYPE == $dot11_BSS_type_independent     Then $Output = "Ad Hoc Only"
                If $DOT11BSSTYPE == $dot11_BSS_type_any             Then $Output = "Any Available Network"
            ElseIf $dwFlag == $wlan_intf_opcode_interface_state Then
                $InterfaceState = DllStructCreate("dword WLANINTERFACESTATE", $pData)
                $WLANINTERFACESTATE = DllStructGetData($InterfaceState, "WLANINTERFACESTATE")
                If $WLANINTERFACESTATE == $wlan_interface_state_connected       Then $Output = "Connected"
                If $WLANINTERFACESTATE == $wlan_interface_state_disconnected    Then $Output = "Disconnected"
                If $WLANINTERFACESTATE == $wlan_interface_state_authenticating  Then $Output = "Authenticating"
            ElseIf $dwFlag == $wlan_intf_opcode_Current_Connection Then
                $ConnectionAttributes = DllStructCreate($WLAN_CONNECTION_ATTRIBUTES, $pData)
                Dim $Output[8]
                $Output[0] = DllStructGetData($ConnectionAttributes, "WLANINTERFACESTATE")
                    If $Output[0] == $wlan_interface_state_connected        Then $Output[0] = "Connected"
                    If $Output[0] == $wlan_interface_state_disconnected     Then $Output[0] = "Disconnected"
                    If $Output[0] == $wlan_interface_state_authenticating   Then $Output[0] = "Authenticating"
                $Output[1] = DllStructGetData($ConnectionAttributes, "strProfileName")
                $Output[2] = DllStructGetData($ConnectionAttributes, "DOT11MACADDRESS")
                    $Output[2] = StringReplace($Output[2], "0x", "")
                    $Output[2] = StringRegExpReplace($Output[2], "[[:xdigit:]]{2}", "\0-", 5)
                $Output[3] = DllStructGetData($ConnectionAttributes, "WLANSIGNALQUALITY")
                $Output[4] = DllStructGetData($ConnectionAttributes, "bSecurityEnabled")
                    If $Output[4] == 1  Then $Output[4] = "Security Enabled"
                    If $Output[4] == 0  Then $Output[4] = "Security Disabled"
                $Output[5] = DllStructGetData($ConnectionAttributes, "bOneXEnabled")
                    If $Output[5] == 1  Then $Output[5] = "802.1x Enabled"
                    If $Output[5] == 0  Then $Output[5] = "802.1x Disabled"
                $Output[6] = DllStructGetData($ConnectionAttributes, "DOT11AUTHALGORITHM")
                    If $Output[6] == $DOT11_AUTH_ALGO_80211_OPEN        Then $Output[6] = "Open"
                    If $Output[6] == $DOT11_AUTH_ALGO_80211_SHARED_KEY  Then $Output[6] = "Shared Key"
                    If $Output[6] == $DOT11_AUTH_ALGO_WPA               Then $Output[6] = "WPA"
                    If $Output[6] == $DOT11_AUTH_ALGO_WPA_PSK           Then $Output[6] = "WPA-PSK"
                    If $Output[6] == $DOT11_AUTH_ALGO_RSNA              Then $Output[6] = "WPA2"
                    If $Output[6] == $DOT11_AUTH_ALGO_RSNA_PSK          Then $Output[6] = "WPA2-PSK"
                $Output[7] = DllStructGetData($ConnectionAttributes, "DOT11CIPHERALGORITHM")
                    If $Output[7] == $DOT11_CIPHER_ALGO_NONE    Then $Output[7] = "Unencrypted"
                    If $Output[7] == $DOT11_CIPHER_ALGO_WEP40   Then $Output[7] = "WEP-64"
                    If $Output[7] == $DOT11_CIPHER_ALGO_TKIP    Then $Output[7] = "TKIP"
                    If $Output[7] == $DOT11_CIPHER_ALGO_CCMP    Then $Output[7] = "AES"
                    If $Output[7] == $DOT11_CIPHER_ALGO_WEP104  Then $Output[7] = "WEP-128"
                    If $Output[7] == $DOT11_CIPHER_ALGO_WEP     Then $Output[7] = "WEP"
                EndIf
                
                _Wlan_FreeMemory($pData)
                
            Return $Output
        EndIf
    EndIf
EndFunc

Func _Wlan_SetInterface($hClientHandle, $pGUID, $dwFlag, $strData)
    Local $Input, $Struct
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    If $pGUID == -1 Or $pGUID == Default Then $pGUID = $GLOBAL_pGUID
    
    If $dwFlag == 0 Then 
        $dwFlag = $wlan_intf_opcode_autoconf_enabled
    ElseIf $dwFlag == 1 Then 
        $dwFlag = $wlan_intf_opcode_bss_type
    EndIf
    
    $AutoConfigState = DllStructCreate("int bool")
    If $dwFlag == $wlan_intf_opcode_autoconf_enabled Then
        $Struct = DllStructCreate("int bool")
        If $strData == "Auto Config Enabled"    Then $Input = 1
        If $strData == "Auto Config Disabled"   Then $Input = 0
        DllStructSetData($Struct, "bool", $Input)
    ElseIf $dwFlag == $wlan_intf_opcode_bss_type Then
        $Struct = DllStructCreate("dword DOT11BSSTYPE")
        If $strData == "Infrastructure Only"    Then $Input = $dot11_BSS_type_infrastructure
        If $strData == "Ad Hoc Only"            Then $Input = $dot11_BSS_type_independent
        If $strData == "Any Available Network"  Then $Input = $dot11_BSS_type_any
        DllStructSetData($Struct, "DOT11BSSTYPE", $Input)
    EndIf
    
    $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanSetInterface", "hwnd", $hClientHandle, "ptr", $pGUID, "dword", $dwFlag, "dword", 4, "ptr", DllStructGetPtr($Struct), "ptr", 0)
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

;----Tools----;

Func _Wlan_StartSession()
    Local $Error, $Extended
    $hClientHandle = _Wlan_OpenHandle()
    If @error <> 0 Then
        SetError(@error, @extended)
        Return $hClientHandle
    EndIf
    
    $InterfaceArray = _Wlan_EnumInterfaces($hClientHandle)
    If @error <> 0 Then
        $Error = @error
        $Extended = @extended
        _Wlan_CloseHandle($hClientHandle)
        Return SetError($Error, $Extended, $InterfaceArray)
    EndIf
    
    _Wlan_SetGlobalConstants($hClientHandle, $InterfaceArray[0][0])

    SetExtended($hClientHandle)
    Return $InterfaceArray
EndFunc

Func _Wlan_EndSession($hClientHandle)
    If $hClientHandle == -1 Or $hClientHandle == Default Then $hClientHandle = $GLOBAL_hClientHandle
    _Wlan_CloseHandle($hClientHandle)
    SetError(@error, @extended)
    DllClose($WLANAPIDLL)
EndFunc

Func _Wlan_SetGlobalConstants($hClientHandle, $pGUID)
    If $hClientHandle <> "" Then Global $GLOBAL_hClientHandle = $hClientHandle
    If $pGUID <> "" Then Global $GLOBAL_pGUID = $pGUID
EndFunc

Func _Wlan_StringTopGuid($strGUID)
    Local $aGUID
    Global $GUIDstruct = DllStructCreate($GUID_STRUCT)
    
    $strGUID = StringRegExpReplace($strGUID, "[}{]", "")
    $aGUID = StringSplit($strGUID, "-")
    
    DllStructSetData($GUIDstruct, "GUIDFIRST", "0x" & $aGUID[1])
    DllStructSetData($GUIDstruct, "GUIDSECOND", "0x" & $aGUID[2])
    DllStructSetData($GUIDstruct, "GUIDTHIRD", "0x" & $aGUID[3])
    DllStructSetData($GUIDstruct, "GUIDFOURTH", "0x" & $aGUID[4] & $aGUID[5])

    Return DllStructGetPtr($GUIDstruct)
EndFunc

Func _Wlan_pGuidToString($pGUID)
    Local $GUIDstruct2, $strGUID = "{"
    Dim $aGUID[5]
    $GUIDstruct2 = DllStructCreate($GUID_STRUCT, $pGUID)
    
    $aGUID[0] = Hex(DllStructGetData($GUIDstruct2, "GUIDFIRST"))
    $aGUID[1] = Hex(DllStructGetData($GUIDstruct2, "GUIDSECOND"), 4)
    $aGUID[2] = Hex(DllStructGetData($GUIDstruct2, "GUIDTHIRD"), 4)
    $aGUID[3] = Hex(StringTrimRight(DllStructGetData($GUIDstruct2, "GUIDFOURTH"), 12), 4)
    $aGUID[4] = StringTrimLeft(DllStructGetData($GUIDstruct2, "GUIDFOURTH"), 6)
    
    For $i = 0 To UBound($aGUID) - 2
        $strGUID = $strGUID & $aGUID[$i] & "-"
    Next
    
    $strGUID = $strGUID & $aGUID[4] & "}"
    
    Return $strGUID
EndFunc

;----Function Dependencies---;

Func _Wlan_ReasonCodeToString($ReasonCode)
    Local $BUFFER
    
    $BUFFER = DllStructCreate("wchar BUFFER[512]")
    DllCall($WLANAPIDLL, "dword", "WlanReasonCodeToString", "dword", $ReasonCode, "dword", 512, "ptr", DllStructGetPtr($BUFFER), "ptr", 0)
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        Return(DllStructGetData($BUFFER, "BUFFER"))
    EndIf
EndFunc

Func _Wlan_BuildListStructString($Header, $Data, $NumberOfItems)
    
    Local $StructString, $StructElements, $StructElements2, $Buffer
    
    $StructString = $Header
    
    For $i = 0 To $NumberOfItems - 1
        $StructString = $StructString & "; " & $Data
    Next
    
    $StructElements = StringSplit($StructString, ";")
    $StructElements2 = $StructElements
    $StructString = ""
    Dim $ElementCount[UBound($StructElements)], $Buffer[UBound($StructElements)]
    
    For $i = 1 To Ubound($StructElements) -1
        For $j = $i To Ubound($StructElements2) -1
            If $i <> $j And $StructElements[$i] == $StructElements2[$j] Then
                If StringInStr($StructElements[$i], "[") <> 0 Then
                    $Buffer[$j] = StringRegExpReplace($StructElements[$i], "[^[]{0,1024}", "" )
                    $StructElements2[$j] = StringRegExpReplace($StructElements2[$j], "[[][[:digit:]]{0,9}[]]", "" )
                Else
                    $Buffer[$j] = ""
                EndIf
            
                $ElementCount[$i] += 1
                
                $StructElements2[$j] = $StructElements2[$j] & $ElementCount[$i] & $Buffer[$j]
            EndIf
        Next
    Next
    
    For $i = 1 To Ubound($StructElements2) -1
        $StructString = $StructString & $StructElements2[$i]
        If $i <> Ubound($StructElements2) -1 Then $StructString = $StructString & ";"
    Next
    
    Return $StructString
    
EndFunc

Func _Wlan_GetErrorMessage($iError)
    Local $tText = DllStructCreate("char Text[4096]")
    DllCall("Kernel32.dll", "int", "FormatMessageA", "int", 0x1000, "hwnd", 0, "int", $iError, "int", 0, "ptr", DllStructGetPtr($tText), "int", 4096, "ptr", 0)
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        Return DllStructGetData($tText, "Text")
    EndIf
EndFunc

Func _Wlan_FreeMemory($ptr)
    DllCall($WLANAPIDLL, "dword", "WlanFreeMemory", "ptr", $ptr)
    If @error <> 0 Then
        SetError(4)
        Return 0
    EndIf
EndFunc

Func _Wlan_RegisterNotification($hClientHandle, $Flag)
    Local $WLAN_NOTIFICATION_CALLBACK
    If $Flag = 1 Then
        $WLAN_NOTIFICATION_CALLBACK = DllCallbackRegister("_WLAN_NOTIFICATION_CALLBACK", "none", "ptr;ptr")
        $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanRegisterNotification", "hwnd", $hClientHandle, "dword", 0X08 , "int", 0, "ptr", DllCallbackGetPtr($WLAN_NOTIFICATION_CALLBACK), "ptr", 0, "ptr", 0, "ptr*", 0)
    Else
        $a_iCall = DllCall($WLANAPIDLL, "dword", "WlanRegisterNotification", "hwnd", $hClientHandle, "dword", 0 , "int", 0, "ptr", 0, "ptr", 0, "ptr", 0, "ptr*", 0)
    EndIf
    
    If @error <> 0 Then
        SetError(4)
        Return 0
    Else
        If $a_iCall[0] <> 0 Then
            $ErrorMessage = _Wlan_GetErrorMessage($a_iCall[0])
            SetError(1, $a_iCall[0])
            Return $ErrorMessage
        EndIf
    EndIf
EndFunc

Func _WLAN_NOTIFICATION_CALLBACK($PTR1, $PTR2)
    Local $NOTIFICATION, $pData, $Data
    $CallbackSSID = ""
    $NOTIFICATION = DllStructCreate($WLAN_NOTIFICATION_DATA, $PTR1)
    $pData = DllStructGetData($NOTIFICATION, "pData")
    $Data = DllStructCreate($WLAN_CONNECTION_NOTIFICATION_DATA, $pData)
    If DllStructGetData($NOTIFICATION, "NotificationCode") == 10 Then $CallbackConnectCount += 1
    If DllStructGetData($NOTIFICATION, "NotificationCode") == 21 Then $CallbackDisconnectCount += 1
    
    If $CallbackConnectCount = 3 Then $CallbackSSID = DllStructGetData($Data, "ucSSID")
EndFunc

any help would be appreciated thanks

Link to comment
Share on other sites

  • Moderators

sparkie,

First, welcome to the AutoIt forums. ;)

Please do not bump your own threads within 24 hrs - it is considered rude here. Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online.

Be patient and someone will answer eventually. Or if not - tough! :evil:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Try _ArrayDisplay($Nets) on your result from _Wlan_GetAvailableNetworkList(). You should see the SSIDs in [n][0] and the signal quality in [n][3] of the array.

;)

Edit: Cool. That was my 10,000th post. My apologies to the management for the, um... "variable quality" of said posts. :evil:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Try _ArrayDisplay($Nets) on your result from _Wlan_GetAvailableNetworkList(). You should see the SSIDs in [n][0] and the signal quality in [n][3] of the array.

;)

Edit: Cool. That was my 10,000th post. My apologies to the management for the, um... "variable quality" of said posts. :evil:

Yes but as i said in the first place _ArrayDisplay($Nets) creates its own gui witch i want it in my list view not to make a pop up box... And the other stuff you said i didn't really understand

Link to comment
Share on other sites

Yes but as i said in the first place _ArrayDisplay($Nets) creates its own gui witch i want it in my list view not to make a pop up box... And the other stuff you said i didn't really understand

The GUI from _ArrayDisplay() wasn't the point I was just indicating where in the 2D array you would find the data you wanted. The SSIDs are in [n][0] and the signal qualities are in [n][3]. The "n" part you would replace with the index of the one you wanted, or a variable to loop through them like this:
For $n = 1 To UBound($Nets) - 1
    ConsoleWrite($n & ": SSID = " & $Nets[$n][0] & ", Signal = " & $Nets[$n][3] & @LF)
Next

You can create ListView items with the same data as easily as a ConsoleWrite() message.

;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

for some reason this is not working i am not getting errors but i am not seeing any wireless networks either

New code

#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include "Native_Wifi_Func_V3_1b.au3"

wireless()


Func wireless()
    Local $msg

    GUICreate("Wireless demo",300,255)
    GUISetState(@SW_SHOW) 
    GUICtrlCreatePic(@scriptdir & "\Black_VRD_Logo.gif", 25, 0, 250, 50)
    Global $listView = GuiCtrlCreateListView("Wireless Network|Signel", 120, 50, 177, 200)

        $refresh = GUICtrlCreateButton("Refresh", 10, 80, 100)
        GUICtrlCreateButton("Connect", 10, 110, 100)
        GUICtrlCreateButton("Advanced", 10, 140, 100)
        GUICtrlCreateButton("Options" , 10 , 170, 100)
    
        Do
        $msg = GUIGetMsg()
        if $msg = $refresh Then
            _GUICtrlListView_DeleteAllItems($listView)
            $Start = _Wlan_StartSession()
            _Wlan_Scan(-1, -1)
            $Nets = _Wlan_GetAvailableNetworkList(-1, -1, 1)
            ;Want to put it in the list view with the SSID and the Signel here
            ;############################################## Test ################################################
            For $n = 1 To UBound($Nets) - 1
            GUICtrlCreateListViewItem($n & $Nets[$n][0] & "|" & $Nets[$n][3] & @LF ,$listView)
            Next
            ;####################################################################################################
            sleep(200)
        EndIf
      
       

    Until $msg = $GUI_EVENT_CLOSE
EndFunc


Func OnAutoItExit()
    _Wlan_EndSession(-1) ;Calls CloseHandle and closes the dll
EndFunc
Edited by sparkie
Link to comment
Share on other sites

Hey man use this as a springboard... (still very rough)

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include "Native_Wifi_Func_V3_1b.au3"
_Wlan_StartSession()
GUICreate("Wireless demo",300,250)
GUICtrlCreatePic("Black_VRD_Logo.gif", 25, 0, 250, 50)
Global $listView = GuiCtrlCreateListView("Wireless Network|Signal", 120, 50, 177, 200)
$Refresh = GUICtrlCreateButton("Refresh", 10, 80, 100)
$Connect = GUICtrlCreateButton("Connect", 10, 110, 100)
$Advanced = GUICtrlCreateButton("Advanced", 10, 140, 100)
$Options = GUICtrlCreateButton("Options" , 10 , 170, 100)
GUISetState()
Refresh()
Main()
Func Main()
    Local $msg
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $Refresh
                Refresh()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    Wend
EndFunc
Func Refresh()
    _GUICtrlListView_BeginUpdate($listView)
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listView))
    _Wlan_Scan(-1, -1)
    $Nets = _Wlan_GetAvailableNetworkList(-1, -1, 0)
    For $i = 0 To UBound($Nets) - 1
        GUICtrlCreateListViewItem($Nets[$i][0] & "|" & $Nets[$i][3], $listView)
    Next
    _GUICtrlListView_EndUpdate($listView)
EndFunc
Func OnAutoItExit()
    _Wlan_EndSession(-1)
EndFunc

Link to comment
Share on other sites

Hey man use this as a springboard... (still very rough)

#include <GuiConstantsEx.au3>#include <GuiListView.au3>#include "Native_Wifi_Func_V3_1b.au3"_Wlan_StartSession()GUICreate("Wireless demo",300,250)GUICtrlCreatePic("Black_VRD_Logo.gif", 25, 0, 250, 50)Global $listView = GuiCtrlCreateListView("Wireless Network|Signal", 120, 50, 177, 200)$Refresh = GUICtrlCreateButton("Refresh", 10, 80, 100)$Connect = GUICtrlCreateButton("Connect", 10, 110, 100)$Advanced = GUICtrlCreateButton("Advanced", 10, 140, 100)$Options = GUICtrlCreateButton("Options" , 10 , 170, 100)GUISetState()Refresh()Main()Func Main()    Local $msg  While 1        $msg = GUIGetMsg()        Switch $msg            Case $Refresh               Refresh()           Case $GUI_EVENT_CLOSE               Exit        EndSwitch   WendEndFuncFunc Refresh()   _GUICtrlListView_BeginUpdate($listView) _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listView))    _Wlan_Scan(-1, -1)  $Nets = _Wlan_GetAvailableNetworkList(-1, -1, 0)    For $i = 0 To UBound($Nets) - 1     GUICtrlCreateListViewItem($Nets[$i][0] & "|" & $Nets[$i][3], $listView) Next    _GUICtrlListView_EndUpdate($listView)EndFuncFunc OnAutoItExit() _Wlan_EndSession(-1)EndFunc
What a pimp ty bro you got aim?

I need a lil more help on connecting your sample script isnt too descriptive and i really cant find support for this any where

Edited by sparkie
Link to comment
Share on other sites

There is help included in the package...

The UDF taps into the wireless fuctionality built into the OS - thus it behaves in the same way. Think of it as a remote control for windows.

Go to network connections - right click on your card - properties - wireless networks

Play around here and you'll soon work out the behavior of the UDF.

At a guess you havn't create a profile for the network you want to connect to?

Try this for debugging.

$ErrMsg = _Wlan_Connect(-1, -1, "SSID")
If @error > 1 Then ConsoleWrite("Err: " & @error & @CRLF)
If @error == 1 Then ConsoleWrite($ErrMsg)
Link to comment
Share on other sites

There is help included in the package...

The UDF taps into the wireless fuctionality built into the OS - thus it behaves in the same way. Think of it as a remote control for windows.

Go to network connections - right click on your card - properties - wireless networks

Play around here and you'll soon work out the behavior of the UDF.

At a guess you havn't create a profile for the network you want to connect to?

Try this for debugging.

$ErrMsg = _Wlan_Connect(-1, -1, "SSID")
If @error > 1 Then ConsoleWrite("Err: " & @error & @CRLF)
If @error == 1 Then ConsoleWrite($ErrMsg)

No i read the entire help file and the sample file and cant figure it out... but no i dont know how to create the profile

i tried

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include "Native_Wifi_Func_V3_1b.au3"

$Start = _Wlan_StartSession()
GUICreate("Wireless demo",350,250)

GUICtrlCreatePic("Black_VRD_Logo.gif", 25, 0, 250, 50)
Global $listView = GuiCtrlCreateListView("Wireless Network|Signal|Encryption", 120, 50, 226, 199)
$Refresh = GUICtrlCreateButton("Refresh", 10, 80, 100)
$Connect = GUICtrlCreateButton("Connect", 10, 110, 100)
$Advanced = GUICtrlCreateButton("Advanced", 10, 140, 100)
$Options = GUICtrlCreateButton("Options" , 10 , 170, 100)
GUISetState()

Refresh()
Main()

Func Main()
    Local $msg
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $Refresh
                Refresh()
            Case $Connect
                Connect()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    Wend
EndFunc

Func Refresh()
    _GUICtrlListView_BeginUpdate($listView)
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($listView))
    _Wlan_Scan(-1, -1)
    global $Nets = _Wlan_GetAvailableNetworkList(-1, -1, 1)
    Global $i
    For $i = 0 To UBound($Nets) - 1
        GUICtrlCreateListViewItem($Nets[$i][0] & "|" & $Nets[$i][3] & "|" & $Nets[$i][4], $listView)
        
    Next
    _GUICtrlListView_EndUpdate($listView)
EndFunc

Func Connect()
    $indexSelected = ControlListView("", "", $listView, "GetSelected")
    $thisSelected = ControlListView("", "", $listView, "GetText", $indexSelected, 0)
    Local $Profile[9] = [$thisSelected, "Infrastructure", "Automatic", $Nets[$i][4], $Nets[$i][5], "802.1x Enabled", "Pass Phrase", "raccoon1", "No Key Index"]
    $Test = _Wlan_SetProfile(-1, -1, $Profile)
    $ProfList = _Wlan_GetProfileList(-1, -1)    ;Ad Hoc profiles are always lowest priority. if cahanged with SetProfileList() or SetProfilePosition() WZC will "fix" it...
    _ArrayDisplay($ProfList, "Retrieved Profile List")
   _Wlan_Connect(-1, -1, $thisSelected)
EndFunc

Func OnAutoItExit()
    _Wlan_EndSession(-1)
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...