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
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
WLAN_INTERFACE_INFO_LIST (Structures)
 
.
Summary
Contains an array of NIC information

C# Definition:

       /// <summary>
       /// Contains an array of NIC information
       /// </summary>
       [StructLayout(LayoutKind.Sequential)]
       public struct WLAN_INTERFACE_INFO_LIST
       {
        /// <summary>
        /// Length of <see cref="InterfaceInfo"/> array
        /// </summary>
        public Int32 dwNumberOfItems;
        /// <summary>
        /// This member is not used by the wireless service. Applications can use this member when processing individual interfaces.
        /// </summary>
        public Int32 dwIndex;
        /// <summary>
        /// Array of WLAN interfaces.
        /// </summary>
        public WLAN_INTERFACE_INFO[] InterfaceInfo;

        /// <summary>
        /// Constructor for WLAN_INTERFACE_INFO_LIST.
        /// Constructor is needed because the InterfaceInfo member varies based on how many adapters are in the system.
        /// </summary>
        /// <param name="pList">the unmanaged pointer containing the list.</param>
        public WLAN_INTERFACE_INFO_LIST(IntPtr pList)
        {
        // The first 4 bytes are the number of WLAN_INTERFACE_INFO structures.
        dwNumberOfItems = Marshal.ReadInt32(pList, 0);

        // The next 4 bytes are the index of the current item in the unmanaged API.
        dwIndex = Marshal.ReadInt32(pList, 4);

        // Construct the array of WLAN_INTERFACE_INFO structures.
        InterfaceInfo = new WLAN_INTERFACE_INFO[dwNumberOfItems];

        for (int i = 0; i <= dwNumberOfItems - 1; i++) {
            // The offset of the array of structures is 8 bytes past the beginning.
            // Then, take the index and multiply it by the number of bytes in the
            // structure.
            // The length of the WLAN_INTERFACE_INFO structure is 532 bytes - this
            // was determined by doing a Marshall.SizeOf(WLAN_INTERFACE_INFO)
            IntPtr pItemList = new IntPtr(pList.ToInt64() + (i * 532) + 8);

            // Construct the WLAN_INTERFACE_INFO structure, marshal the unmanaged
            // structure into it, then copy it to the array of structures.
            InterfaceInfo[i] = (WLAN_INTERFACE_INFO)Marshal.PtrToStructure(pItemList, typeof(WLAN_INTERFACE_INFO));
        }
       }
      }

VB Definition:

     <StructLayout(LayoutKind.Sequential)> _
    Private Structure WLAN_INTERFACE_INFO_LIST
    Public dwNumberofItems As Int32
    Public dwIndex As Int32
    Public InterfaceInfo As WLAN_INTERFACE_INFO()

    Public Sub New(pList As IntPtr)
        ' The first 4 bytes are the number of WLAN_INTERFACE_INFO structures.
        dwNumberofItems = Marshal.ReadInt32(pList, 0)

        ' The next 4 bytes are the index of the current item in the unmanaged API.
        dwIndex = Marshal.ReadInt32(pList, 4)

        ' Construct the array of WLAN_INTERFACE_INFO structures.
        InterfaceInfo = New WLAN_INTERFACE_INFO(dwNumberofItems - 1) {}

        For i As Integer = 0 To dwNumberofItems - 1
        ' The offset of the array of structures is 8 bytes past the beginning.
        ' Then, take the index and multiply it by the number of bytes in the
        ' structure.
        ' The length of the WLAN_INTERFACE_INFO structure is 532 bytes - this
        ' was determined by doing a Marshall.SizeOf(WLAN_INTERFACE_INFO)
        Dim pItemList As New IntPtr(pList.ToInt64() + (i * 532) + 8)

        ' Construct the WLAN_INTERFACE_INFO structure, marshal the unmanaged
        ' structure into it, then copy it to the array of structures.
        InterfaceInfo(i) = DirectCast(Marshal.PtrToStructure(pItemList, GetType(WLAN_INTERFACE_INFO)), WLAN_INTERFACE_INFO)
        Next
    End Sub

    End Structure

User-Defined Field Types:

WLAN_INTERFACE_INFO

Notes:

The constructor of this structure "unmarshal" WLAN_INTERFACE_INFO_LIST data obtained by calling WlanEnumInterfaces(). This is a good example on how to marshal pointer-to-pointer case in C++ world ( kind of confusing because in C# or Managed Environment more broadly, it is just reference, so as you can see from the implementation for C#, it is to be treated like just a single pointer case. Also, this example shows how to handle an array for the InterfaceInfo inside of this structure. It needs two level of marshaling and this example shows that.

Documentation

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

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