0

in order to connecto to an open access point I fill the WLAN_CONNECTION_PARAMETERS structure as below

WLAN_CONNECTION_PARAMETERS ConnectionParameters;
ConnectionParameters.wlanConnectionMode = wlan_connection_mode_discovery_unsecure;
ConnectionParameters.strProfile         = L"";
ConnectionParameters.pDot11Ssid         = &Dot11Ssid;
ConnectionParameters.pDesiredBssidList  = nullptr;
ConnectionParameters.dot11BssType       = dot11_BSS_type_independent;
ConnectionParameters.dwFlags            = WLAN_CONNECTION_ADHOC_JOIN_ONLY;

The WlanConnect() function returns ERROR_SUCCESS.

The NotificationCallback() function prints:

wlan_notification_acm_connection_start
Currently connecting to "BT.03" using profile "BT.03" **// Correct**
WLAN_NOTIFICATION_SOURCE_ACM
**wlan_notification_acm_connection_attempt_fail**
The connection failed. wlanReasonCode:  163851
The reason is "La rete specificata non è disponibile."

Where is the error?

Have you got a piece of code to connect to a new open wireless access point with a specific ssid?

Dai
  • 141,631
  • 28
  • 261
  • 374
  • Please post the code that sets-up `Dot11Ssid`. – Dai Dec 28 '20 at 16:41
  • Your code says `strProfile = L""` but your output display says "BT.03". Please post your **actual** code or make it clear you're obfuscating secrets. – Dai Dec 28 '20 at 16:44

2 Answers2

1

The documentation for WLAN_CONNECTION_PARAMETERS states that strProfile should be set to NULL when using wlan_connection_mode_discovery_unsecure, but your code sets it to L"".

If wlanConnectionMode is set to wlan_connection_mode_discovery_secure or wlan_connection_mode_discovery_unsecure, then strProfile should be set to NULL.

So change your code to this:

ConnectionParameters.strProfile = NULL;
Dai
  • 141,631
  • 28
  • 261
  • 374
  • @DenisGottardello `nullptr` isn't the same thing as `NULL` though. Win32 is still a C (not C++) API, so always use `NULL` instead of `nullptr` when using Win32. – Dai Dec 28 '20 at 18:43
  • @DenisGottardello Just edit your original question. – Dai Dec 28 '20 at 19:45
0

ConnectionParameters.strProfile= nullptr;

don't resolve.

The solution is to add

memset(&ConnectionParameters, 0, sizeof(WLAN_CONNECTION_PARAMETERS));