WlanEnumInterfaces 函数枚举本地计算机上当前启用的所有无线 LAN 接口。
语法
DWORD WlanEnumInterfaces(
  [in]  HANDLE                    hClientHandle,
  [in]  PVOID                     pReserved,
  [out] PWLAN_INTERFACE_INFO_LIST *ppInterfaceList
);
参数
[in] hClientHandle
客户端的会话句柄,由先前对 WlanOpenHandle 函数的调用获取。
[in] pReserved
保留供将来使用。 此参数必须设置为 NULL。
[out] ppInterfaceList
指向存储的指针,用于接收 WLAN_INTERFACE_INFO_LIST 结构中无线 LAN 接口的返回列表。
如果调用成功,则返回 WLAN_INTERFACE_INFO_LIST 的缓冲区由 WlanEnumInterfaces 函数分配。
返回值
如果函数成功,则返回值为 ERROR_SUCCESS。
如果函数失败,则返回值可能是以下返回代码之一。
| 返回代码 | 说明 | 
|---|---|
| 
 | 参数不正确。 如果 hClientHandle 或 ppInterfaceList 参数为 NULL,则返回此错误。 如果 pReserved 不为 NULL,则返回此错误。 如果 hClientHandle 参数无效,也会返回此错误。 | 
| 
 | 在句柄表中找不到句柄 hClientHandle 。 | 
| 
 | 各种错误代码。 | 
| 
 | 没有足够的内存可用于处理此请求并为查询结果分配内存。 | 
注解
当函数成功时, WlanEnumInterfaces 函数为返回的接口列表分配内存,这些接口在 ppInterfaceList 参数指向的缓冲区中返回。 不再需要缓冲区后,应通过调用 WlanFreeMemory 函数释放用于 ppInterfaceList 参数指向的缓冲区的内存。
示例
以下示例枚举本地计算机上的无线 LAN 接口,并从检索到 的 WLAN_INTERFACE_INFO_LIST 结构和枚举 的 WLAN_INTERFACE_INFO 结构中 输出值。
              注意 如果未安装并启动无线 LAN 服务,此示例将无法在 Windows Server 2008 和 Windows Server 2008 R2 上加载。
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <wlanapi.h>
#include <objbase.h>
#include <wtypes.h>
#include <stdio.h>
#include <stdlib.h>
// Need to link with Wlanapi.lib and Ole32.lib
#pragma comment(lib, "wlanapi.lib")
#pragma comment(lib, "ole32.lib")
int wmain()
{
    // Declare and initialize variables.
    HANDLE hClient = NULL;
    DWORD dwMaxClient = 2;   //    
    DWORD dwCurVersion = 0;
    DWORD dwResult = 0;
    int iRet = 0;
    
    WCHAR GuidString[40] = {0};
     
    int i;
    /* variables used for WlanEnumInterfaces  */
    
    PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
    PWLAN_INTERFACE_INFO pIfInfo = NULL;
    
    dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient); 
    if (dwResult != ERROR_SUCCESS)  {
        wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
        // FormatMessage can be used to find out why the function failed
        return 1;
    }
    
    dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList); 
    if (dwResult != ERROR_SUCCESS)  {
        wprintf(L"WlanEnumInterfaces failed with error: %u\n", dwResult);
        // FormatMessage can be used to find out why the function failed
        return 1;
    }
    else {
        wprintf(L"Num Entries: %lu\n", pIfList->dwNumberOfItems);
        wprintf(L"Current Index: %lu\n", pIfList->dwIndex);
        for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) {
            pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
            wprintf(L"  Interface Index[%d]:\t %lu\n", i, i);
            iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString, 39); 
            // For c rather than C++ source code, the above line needs to be
            // iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString, 39); 
            if (iRet == 0)
                wprintf(L"StringFromGUID2 failed\n");
            else {
                wprintf(L"  InterfaceGUID[%d]: %ws\n",i, GuidString);
            }    
            wprintf(L"  Interface Description[%d]: %ws", i, 
                pIfInfo->strInterfaceDescription);
            wprintf(L"\n");
            wprintf(L"  Interface State[%d]:\t ", i);
            switch (pIfInfo->isState) {
            case wlan_interface_state_not_ready:
                wprintf(L"Not ready\n");
                break;
            case wlan_interface_state_connected:
                wprintf(L"Connected\n");
                break;
            case wlan_interface_state_ad_hoc_network_formed:
                wprintf(L"First node in a ad hoc network\n");
                break;
            case wlan_interface_state_disconnecting:
                wprintf(L"Disconnecting\n");
                break;
            case wlan_interface_state_disconnected:
                wprintf(L"Not connected\n");
                break;
            case wlan_interface_state_associating:
                wprintf(L"Attempting to associate with a network\n");
                break;
            case wlan_interface_state_discovering:
                wprintf(L"Auto configuration is discovering settings for the network\n");
                break;
            case wlan_interface_state_authenticating:
                wprintf(L"In process of authenticating\n");
                break;
            default:
                wprintf(L"Unknown state %ld\n", pIfInfo->isState);
                break;
            }
            wprintf(L"\n");
        }
    }
    if (pIfList != NULL) {
        WlanFreeMemory(pIfList);
        pIfList = NULL;
    }
    return 0;
}
要求
| 最低受支持的客户端 | Windows Vista、Windows XP SP3 [仅限桌面应用] | 
| 最低受支持的服务器 | Windows Server 2008 [仅限桌面应用] | 
| 目标平台 | Windows | 
| 标头 | wlanapi.h (包括 Wlanapi.h) | 
| Library | Wlanapi.lib | 
| DLL | Wlanapi.dll | 
| 可再发行组件 | 带有 SP2 的 Windows XP 无线 LAN API |