Search code examples
c++windowswlanapi

WlanQueryInterface data enumeration


I want to get wlan_intf_opcode_bss_type using WlanQueryInterface function.

My code:

PDOT11_BSS_TYPE wlanInterfaceState = NULL;
DWORD wlanInterfaceStateSize = sizeof(wlanInterfaceState);
DWORD interfaceStateResult;
interfaceStateResult = WlanQueryInterface(hClient, &pIfInfo->InterfaceGuid, wlan_intf_opcode_bss_type, NULL, &wlanInterfaceStateSize, (PVOID *)&wlanInterfaceState, NULL);

if (interfaceStateResult != ERROR_SUCCESS) {
  qDebug() << "Error";
} else {
  qDebug() << wlanInterfaceState;
}

I get hexadecimal values. When I use switch to enumerate on wlanInterfaceState I get error:

error: C2450: switch expression of type 'PDOT11_BSS_TYPE' is illegal

Update: DOT11_BSS_TYPE enumeration syntax from MSDN:

typedef enum _DOT11_BSS_TYPE { 
  dot11_BSS_type_infrastructure  = 1,
  dot11_BSS_type_independent     = 2,
  dot11_BSS_type_any             = 3
} DOT11_BSS_TYPE, *PDOT11_BSS_TYPE;

How to use these enumerations on wlanInterfaceState? Thanks.


Solution

  • The problem was that I use the pointer wlanInterfaceState version, so using it with switch is not considered correct expression.

    Switch (condition) statement

    condition - any expression of integral or enumeration type, or of a class type contextually implicitly convertible to an integral or enumeration type, or a declaration of a single non-array variable of such type with a brace-or-equals initializer.

    Since it points to enum, then I need to dereference it.

    So the switch statement should look like this:

     switch (*wlanInterfaceState) {
             case dot11_BSS_type_infrastructure:
                  qDebug() << "Infastructure";
             break;
    
             case dot11_BSS_type_independent:
                  qDebug() << "Independent";
             break;
    
             case dot11_BSS_type_any:
                  qDebug() << "Any";
             break;
    
             default:
                  qDebug() << "Unknown";
             }