Search code examples
c++windowswifiwlanapi

Wlan connection issue


I want to connect to the wireless access point using WlanConnect function.

Code:

HANDLE hClient;
PWLAN_INTERFACE_INFO_LIST pIfList;
PWLAN_INTERFACE_INFO pIfInfo;
PWLAN_AVAILABLE_NETWORK_LIST pBssList;

DWORD dwResult = 0;
WLAN_CONNECTION_PARAMETERS connectionParameters;
memset(&connectionParameters, 0, sizeof(WLAN_CONNECTION_PARAMETERS));
connectionParameters.wlanConnectionMode = wlan_connection_mode_profile;
connectionParameters.strProfile = pBssList->Network[apIndex].strProfileName;
connectionParameters.dwFlags = 0;
connectionParameters.pDot11Ssid = NULL;
connectionParameters.pDesiredBssidList = 0;
connectionParameters.dot11BssType = dot11_BSS_type_any;
dwResult = WlanConnect(hClient, &pIfInfo->InterfaceGuid, &connectionParameters, NULL);

if (dwResult == ERROR_SUCCESS) {
    qDebug() << "Connected!";
} else {
    qDebug() << dwResult;
}

When connecting to open AP I get 87 error code, it means the wrong parameter. Any ideas what parameter can be wrong? Thanks in advance.


Solution

  • I have figured it out and fixed the issue. The issue was that the WlanSetProfile function was not set before the WlanConnect function.