-3

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.

Cobra91151
  • 610
  • 4
  • 14
  • 1) Please provide [mcve]. You are asking for which parameter might be wrong, but you don't provide the code, where you set half of them. 2) Did you look at the [documentation](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706613(v=vs.85).aspx)? To be more precise, the section about `ERROR_INVALID_PARAMETER` which lists under which conditions such error code may be returned. – Algirdas Preidžius Aug 14 '17 at 14:10
  • @AlgirdasPreidžius I have tested different parameters. The result is the same - `87`. I can't post all wireless code because it has > 700 lines. – Cobra91151 Aug 14 '17 at 20:00
  • 1) Please show me, where I asked to post **all** the code. I asked for, **manufactured**, [mcve]. 2) your code sample, as presented exhibits undefined behavior due to `&pIfInfo->InterfaceGuid`, since `pIfInfo` is uninitialized, and using `hClient`, in the same line, which is also uninitialized. 3) As code sample is presented - all I could suggest is re-read the documentation. More specifically - the section about `ERROR_INVALID_PARAMETER`, instead of trying to guess the reason. – Algirdas Preidžius Aug 14 '17 at 22:08

1 Answers1

0

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

Cobra91151
  • 610
  • 4
  • 14