Search code examples
c++windowswifi

Why windows wifi API 'WlanEnumInterfaces' is failed with 'ERROR_INVALID_STATE'?


I am trying to enumerate the WiFi networks with windows API. But I don't know why it fails with the error code ERROR_INVALID_STATE . Below is my sample code

PWLAN_INTERFACE_INFO_LIST  pIfList = NULL;
    
    DWORD dwNegotiatedVersion;
    HANDLE hClientHandle;
    DWORD Res=WFDOpenHandle(WFD_API_VERSION, &dwNegotiatedVersion, &hClientHandle);
    if (Res != ERROR_SUCCESS)
    {
        WFDCloseHandle(hClientHandle);
        return;
    }
    Res = WlanEnumInterfaces(hClientHandle, NULL, &pIfList);
    if (Res == ERROR_INVALID_STATE)
    {
        WlanCloseHandle(hClientHandle, NULL);
        return;
    }
    else if (Res != ERROR_SUCCESS) 
    {
        WlanCloseHandle(hClientHandle, NULL);
        return;
    }

I am using Windows 10.and debugging using visual studio 2015


Solution

  • The handle for WlanEnumInterfaces is a handle from WlanOpenHandle - as stated in the documentation. It is not a WFD handle from WFDOpenHandle.