Results 1 to 10 of 10

Thread: Cant find DLL entry

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2011
    Posts
    108

    Cant find DLL entry

    Hi,

    I'm tring to declare a function in VB6 in wlanapi.dll
    Here's the function:

    Code:
    Private Declare Function WlanHostedNetworkQueryStatus Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
                    ppWlanHostedNetworkStatus As String, _
                    ByVal pReserved As Long) As Long
    I'm not sure if the ppWlanHostedNetworkStatus variable is a string, but that's not the error, I think (error 453)

    Can someone help me out here?

    Kind regards,

    JKepler

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Cant find DLL entry

    Are you running W7 or above (that's a prerequisite)

    The ppWlanHostedNetworkStatus should be a Long - it's a pointer to the Status.

    (http://msdn.microsoft.com/en-us/libr...v=vs.85).aspx)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2011
    Posts
    108

    Re: Cant find DLL entry

    Hi,

    Thanks for the reply. I'm trying to run it in XP SP3...
    Thanks for the variable type information. Is there a similar DLL that can check the status of the WLAN in the differents Windows version?

    Regards,

    JKepler
    Last edited by jkepler; Jul 4th, 2014 at 12:00 PM.

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Cant find DLL entry

    Looks like WlanQueryInterface can do it. http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2011
    Posts
    108

    Re: Cant find DLL entry

    Hi,

    I've declared:

    Private Type WLAN_INTERFACE_STATE
    wlan_interface_state_not_ready As Long
    wlan_interface_state_connected As Long
    wlan_interface_state_ad_hoc_network_formed As Long
    wlan_interface_state_disconnecting As Long
    wlan_interface_state_disconnected As Long
    wlan_interface_state_associating As Long
    wlan_interface_state_discovering As Long
    wlan_interface_state_authenticating As Long
    End Type

    'wlan_interface_state_not_ready = 0
    'wlan_interface_state_connected = 1
    'wlan_interface_state_ad_hoc_network_formed = 2
    'wlan_interface_state_disconnecting = 3
    'wlan_interface_state_disconnected = 4
    'wlan_interface_state_associating = 5
    'wlan_interface_state_discovering = 6
    'wlan_interface_state_authenticating = 7


    and

    Private Declare Function WlanQueryInterface Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
    pInterfaceGuid As GUID, _
    ByVal OpCode As Long, _
    ByVal pReserved As Long, _
    pdwDataSize As Long, _
    ppData As Long, _
    pWlanOpcodeValueType As Long) As Long

    I'm trying to call it like this:

    lngStatus = WlanQueryInterface(lngHandle, pInterfaceGuid, 1, 0&, 8, ppData, WStatus)

    I think I'm not doing it right.....

    Where's the satus? In wich variable?

    I really need help....

    JKepler

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Cant find DLL entry

    I've been having a play and it's not quite as straightforward as imagined. Have a play with this; it scans for available networks and for each WLAN adapter reports the network they're connected to (if any)
    Code:
    Option Explicit
    
    Private Const WLAN_MAX_PHY_TYPE_NUMBER As Long = 8
    Private Const DOT11_SSID_MAX_LENGTH As Long = 32
    Private Const ERROR_SUCCESS = 0&
    
    Private Type GUID
        data1 As Long
        data2 As Integer
        data3 As Integer
        data4(7) As Byte
    End Type
    
    Private Type DOT11_SSID
        uSSIDLength As Long
        ucSSID(DOT11_SSID_MAX_LENGTH - 1) As Byte
    End Type
    
    
    Private Type WLAN_AVAILABLE_NETWORK
        strProfileName(511) As Byte
        dot11Ssid As DOT11_SSID
        dot11BssType As Long
        uNumberOfBssids As Long
        bNetworkConnectable As Long
        wlanNotConnectableReason As Long
        uNumberOfPhyTypes As Long
        dot11PhyTypes(WLAN_MAX_PHY_TYPE_NUMBER - 1) As Long
        bMorePhyTypes As Long
        wlanSignalQuality As Long
        bSecurityEnabled As Long
        dot11DefaultAuthAlgorithm As Long
        dot11DefaultCipherAlgorithm As Long
        dwFlags As Long
        dwreserved As Long
    End Type
    
    Private Type WLAN_AVAILABLE_NETWORK_LIST
        dwNumberofItems As Long
        dwIndex As Long
        Network As WLAN_AVAILABLE_NETWORK
    End Type
    
    Private Type WLAN_INTERFACE_INFO
        ifGuid As GUID
        InterfaceDescription(255) As Byte
        IsState As Long
    End Type
    
    Private Type WLAN_INTERFACE_INFO_LIST
        dwNumberofItems As Long
        dwIndex As Long
        InterfaceInfo As WLAN_INTERFACE_INFO
    End Type
    
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
                    Source As Any, _
                    ByVal Length As Long)
                    
    Private Declare Function CreateEvent Lib "kernel32" Alias "CreateEventA" _
                    (lpEventAttributes As Long, _
                     ByVal bManualReset As Long, _
                     ByVal bInitialState As Long, _
                     ByVal lpName As String) As Long
                     
    Private Declare Function WaitForSingleObject Lib "kernel32" _
                    (ByVal hHandle As Long, _
                     ByVal dwMilliseconds As Long) As Long
                     
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    
    Private Declare Function WlanOpenHandle Lib "wlanapi.dll" (ByVal dwClientVersion As Long, _
                    ByVal pdwReserved As Long, _
                    ByRef pdwNegotiaitedVersion As Long, _
                    ByRef phClientHandle As Long) As Long
    
    Private Declare Function WlanEnumInterfaces Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
                    ByVal pReserved As Long, _
                    ppInterfaceList As Long) As Long
                    
    Private Declare Function WlanGetAvailableNetworkList Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
                    pInterfaceGuid As GUID, _
                    ByVal dwFlags As Long, _
                    ByVal pReserved As Long, _
                    ppAvailableNetworkList As Long) As Long
    
    Private Declare Function WlanScan Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
                    pInterfaceGuid As GUID, _
                    pDot11Ssid As Long, _
                    pIeData As Long, _
                    reserved As Long) As Long
                    
    Private Declare Sub WlanFreeMemory Lib "wlanapi.dll" (ByVal pMemory As Long)
                    
    Private lngEvent As Long
    Private lngHandle As Long
    Private lngList As Long
    Private lngAvailable As Long
    
    Private Sub cmdCheckConnected_Click()
    Dim udtList As WLAN_INTERFACE_INFO_LIST
    Dim udtInfo As WLAN_INTERFACE_INFO
    Dim udtAvailableList As WLAN_AVAILABLE_NETWORK_LIST
    Dim udtNetwork As WLAN_AVAILABLE_NETWORK
    
    Dim intCount As Integer
    Dim intCount1 As Integer
    Dim lngReturn As Long
    Dim lngStart As Long
    Dim lngStart1 As Long
    Dim lngVersion As Long
    Dim binConnected As Boolean
    Dim strProfile As String
    Dim strSSID As String
    Dim strInterface As String
    
    lngReturn = WlanOpenHandle(2&, 0&, lngVersion, lngHandle)
    If lngReturn = 0 Then
        lngEvent = CreateEvent(0&, True, False, "Dummy")
        '
        ' Enumerate the WLAN Interfaces
        '
        lngReturn = WlanEnumInterfaces(ByVal lngHandle, 0&, lngList)
        CopyMemory udtList, ByVal lngList, Len(udtList)
        If udtList.dwNumberofItems > 0 Then
            '
                ' Scan for available Networks
                ' This will take 4.5 seconds elapsed
                '
            If Scan(udtList.InterfaceInfo.ifGuid) Then
                lngStart1 = lngList + 8
                '
                ' For each WLAN Interface get the available netwok list
                '
                Do
                    binConnected = False
                    CopyMemory udtInfo, ByVal lngStart1, Len(udtInfo)
                    lngReturn = WlanGetAvailableNetworkList(lngHandle, udtList.InterfaceInfo.ifGuid, 2&, 0&, lngAvailable)
                    CopyMemory udtAvailableList, ByVal lngAvailable, LenB(udtAvailableList)
                    intCount = 0
                    lngStart = lngAvailable + 8
                    '
                    ' Get the various attributes of each available network
                    ' and see if it's connected
                    Do
                        CopyMemory udtNetwork, ByVal lngStart, Len(udtNetwork)
                        strProfile = ByteToString(udtNetwork.strProfileName)
                        strProfile = Left$(strProfile, InStr(strProfile, Chr(0)) - 1)
                        strInterface = Left$(udtInfo.InterfaceDescription, InStr(udtInfo.InterfaceDescription, Chr(0)) - 1)
                        strSSID = ByteToString(udtNetwork.dot11Ssid.ucSSID, udtNetwork.dot11Ssid.uSSIDLength, False)
                        strSSID = Left(strSSID, InStr(strSSID, Chr(0)) - 1)
                        If (udtNetwork.dwFlags And 1) <> 0 Then
                            Debug.Print strInterface; " Connected to "; strSSID
                            binConnected = True
                        End If
                        intCount = intCount + 1
                        lngStart = lngStart + Len(udtNetwork)
                    Loop Until intCount = udtAvailableList.dwNumberofItems
                    If Not binConnected Then
                        Debug.Print strInterface; " Not connected"
                    End If
    
                    intCount1 = intCount1 + 1
                    lngStart1 = lngStart1 + Len(udtList)
                Loop Until intCount1 = udtList.dwNumberofItems
            Else
                MsgBox "Scan Failed"
            End If
        Else
            MsgBox "No WLAN Adapters Found"
        End If
    Else
        MsgBox "Unable to Access Wlan"
    End If
    End Sub
    
    Private Function Scan(udtGuid As GUID) As Boolean
    Dim lngReturn As Long
    labScan.Visible = True
    labScan.Refresh
    lngReturn = WlanScan(lngHandle, udtGuid, ByVal 0&, ByVal 0&, ByVal 0&)
    If lngReturn = ERROR_SUCCESS Then
        Scan = True
    Else
        Scan = False
    End If
    lngReturn = WaitForSingleObject(lngEvent, 4500&)
    labScan.Visible = False
    End Function
    
    Private Function ByteToString(bytArray() As Byte, Optional lngLen As Long = 0, Optional boConvert As Boolean = True) As String
    Dim strTemp As String
    Dim intI As Integer
    Dim intEnd As Integer
    If lngLen = 0 Then
        intEnd = UBound(bytArray)
    Else
        intEnd = lngLen
    End If
    For intI = 0 To intEnd
        strTemp = strTemp & Chr(bytArray(intI))
    Next intI
    If boConvert = True Then strTemp = StrConv(strTemp, vbFromUnicode)
    ByteToString = strTemp
    End Function
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    '
    ' IMPORTANT TO TIDY UP WHEN FINISHED
    '
    Dim lngRet As Long
    WlanFreeMemory lngAvailable
    WlanFreeMemory lngList
    lngRet = CloseHandle(lngHandle)
    End Sub
    You need a Form with a CommandButton named cmdCheck and a Label named LabScan with a Caption of "Scanning.." with the Visible Property set to False.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2011
    Posts
    108

    Re: Cant find DLL entry

    Quite a code!!!

    Can you get WlanDisconnect to functioning? I cant...

    JKepler

  8. #8
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Cant find DLL entry

    It's quite straightforward. You need to add another API reference
    Code:
    Private Declare Function WlanDisconnect Lib "wlanapi.dll" (ByVal hClientHandle As Long, _
                    pInterfaceGuid As GUID, _
                    ByVal pReserved As Long) As Long
    and then call it
    Code:
    Private Sub cmdDisconnect_Click()
    Dim lngReturn As Long
    lngReturn = WlanDisconnect(lngHandle, udtList.InterfaceInfo.ifGuid, 0&)
    If lngReturn = ERROR_SUCCESS Then
        boConnected = False
    End If
    End Sub

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2011
    Posts
    108

    Re: Cant find DLL entry

    You're.... a genius. Seriously. I made some test to connect the wireless, disconnet and gather info.
    But how to shut down the wireless permantly? Is there a solution? The WlanDisconnect only disconnects, it doesnt shut dows.

    JKepler

  10. #10
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Cant find DLL entry

    That's a different kettle of fish. What exactly are you trying to do?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width