Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

WlanQueryInterface (wlanapi)
 
.
Summary
Queries various parameters of a specified interface

C# Signature:

        [DllImport("Wlanapi", EntryPoint = "WlanQueryInterface")]
        public static extern uint WlanQueryInterface([In] IntPtr hClientHandle,
        [In] ref Guid pInterfaceGuid,
        WLAN_INTF_OPCODE OpCode,
        IntPtr pReserved,
        [Out] out uint pdwDataSize,
        ref IntPtr ppData,
        IntPtr pWlanOpcodeValueType);

VB Signature:

     <DllImport("Wlanapi", EntryPoint := "WlanQueryInterface")> _
     Public Shared Function WlanQueryInterface(<[In]> ByVal hClientHandle As IntPtr, _
    <[In]> ByRef pInterfaceGuid As Guid, ByVal OpCode As WLAN_INTF_OPCODE, _
    ByVal pReserved As IntPtr, <Out> ByRef pdwDataSize As UInteger, _
    ByRef ppData As IntPtr, ByVal pWlanOpcodeValueType As IntPtr) As UInteger
     End Function

User-Defined Types:

WLAN_INTF_OPCODE

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Depending on the opcode, the data returned in the memory pointed to by ppData can be:

WLAN_RADIO_STATE

"DOT11_BSS_TYPE"

WLAN_INTERFACE_STATE

WLAN_CONNECTION_ATTRIBUTES

WLAN_AUTH_CIPHER_PAIR_LIST

WLAN_COUNTRY_OR_REGION_STRING_LIST

WLAN_STATISTICS

Tips & Tricks:

Please add some!

Sample Code:

C#

       IntPtr handle = IntPtr.Zero;
       uint negotiatedVersion;        
       try
       {    
        if (WlanOpenHandle(1, IntPtr.Zero, out negotiatedVersion, ref handle) != 0)
            return;

        IntPtr ptr = new IntPtr();
        if (WlanEnumInterfaces(handle, IntPtr.Zero, ref ptr) != 0)
            return;

        WLAN_INTERFACE_INFO_LIST infoList = new WLAN_INTERFACE_INFO_LIST(ptr);
        WlanFreeMemory(ptr);

        Guid guid;
        uint dataSize;
        WLAN_CONNECTION_ATTRIBUTES connection;
        // Call wlanqueryinterface for all the interfaces in the list
        for (int i = 0; i < infoList.dwNumberOfItems; i++)
        {
            guid = infoList.InterfaceInfo[i].InterfaceGuid;
            if (WlanQueryInterface(handle, ref guid, WLAN_INTF_OPCODE.wlan_intf_opcode_current_connection, IntPtr.Zero, out dataSize, ref ptr, IntPtr.Zero) != 0)
            return;

            connection = (WLAN_CONNECTION_ATTRIBUTES)Marshal.PtrToStructure(ptr, typeof(WLAN_CONNECTION_ATTRIBUTES));

            // Do something here with the connection info....    
            WlanFreeMemory(ptr);
        }
        }
        finally
        {
        if (handle != IntPtr.Zero)
            WlanCloseHandle(handle, IntPtr.Zero);
        }

VB.NET

     Dim handle As IntPtr = IntPtr.Zero
     Dim negotiatedVersion As UInteger
     Try
     If WlanOpenHandle(1, IntPtr.Zero, negotiatedVersion, handle) <> 0 Then
         Return
     End If

     Dim ptr As New IntPtr()
     If WlanEnumInterfaces(handle, IntPtr.Zero, ptr) <> 0 Then
         Return
     End If

     Dim infoList As New WLAN_INTERFACE_INFO_LIST(ptr)
     WlanFreeMemory(ptr)

     Dim guid As Guid
     Dim dataSize As UInteger
     Dim connection As WLAN_CONNECTION_ATTRIBUTES
     ' Call wlanqueryinterface for all the interfaces in the list
     For i As Integer = 0 To infoList.dwNumberOfItems - 1
         guid = infoList.InterfaceInfo(i).InterfaceGuid
         If WlanQueryInterface(handle, guid, WLAN_INTF_OPCODE.wlan_intf_opcode_current_connection, IntPtr.Zero, dataSize, ptr, _
         IntPtr.Zero) <> 0 Then
         Return
         End If

         connection = DirectCast(Marshal.PtrToStructure(ptr, GetType(WLAN_CONNECTION_ATTRIBUTES)), WLAN_CONNECTION_ATTRIBUTES)

         ' Do something here with the connection info....
         WlanFreeMemory(ptr)
     Next
     Finally
     If handle <> IntPtr.Zero Then
         WlanCloseHandle(handle, IntPtr.Zero)
     End If
     End Try

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions