C++/QT获取、连接wifi

C++/QT获取、连接wifi

操作wifi的库

#include 
#pragma comment(lib, "wlanapi.lib")
#pragma comment(lib, "ole32.lib")

获取wlan的handle、接口信息Interface Info

WlanOpenHandle
WlanEnumInterfaces

HANDLE hClient = NULL;
DWORD dwMaxClient = 2;
DWORD dwCurVersion = 0;
DWORD dwResult = 0;

PWLAN_INTERFACE_INFO_LIST pIfList = NULL;

dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (ERROR_SUCCESS != dwResult)
{
   
   qDebug() << "WlanOpenHandle failed with error:" << dwResult;
   //return false;
}
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (ERROR_SUCCESS != dwResult)
{
   
   qDebug() << "WlanEnumInterfaces failed with error" << dwResult;
   //return false;
}

询问是否有已连接的wifi

WlanQueryInterface: 判断是否有已连接的wifi

PWLAN_CONNECTION_ATTRIBUTES pConnectInfo = NULL;
DWORD connectInfoSize = sizeof(WLAN_CONNECTION_ATTRIBUTES);
WLAN_OPCODE_VALUE_TYPE opCode = wlan_opcode_value_type_invalid;
PWLAN_INTERFACE_INFO pIfInfo = NULL;
pIfInfo = (WLAN_INTERFACE_INFO*)&pIfList->InterfaceInfo[i];
QString CurConnectedWlanProfileName{
    "" };
if (pIfInfo->isState == wlan_interface_state_connected)
{
   
    dwResult = WlanQueryInterface(hClient,
    &pIfInfo->InterfaceGuid,
     wlan_intf_opcode_current_connection,
     NULL,
     &connectInfoSize,
     (PVOID *)&pConnectInfo,
     &opCode);
     if (dwResult != ERROR_SUCCESS)
     {
   
         qDebug() << "WlanQueryInterface failed with error" << dwResult;
     }
     else
     {
   
         switch (pConnectInfo->isState)
         {
   
         case wlan_interface_state_connected:
         {
   
             // 配置文件名和wifi名相同
             CurConnectedWlanProfileName = QString::fromWCharArray(pConnectInfo->strProfileName);
             qDebug() << &#

你可能感兴趣的:(c++,c++,qt,wifi,windows)