query method

String? query(
  1. WlanQuery query
)

Implementation

String? query(WlanQuery query) {
  openHandle();
  final ppInterfaceList = calloc<Pointer<WLAN_INTERFACE_INFO_LIST>>();

  try {
    var hr = WlanEnumInterfaces(clientHandle, nullptr, ppInterfaceList);
    if (hr != ERROR_SUCCESS) return null; // no wifi interface available

    for (var i = 0; i < ppInterfaceList.value.ref.dwNumberOfItems; i++) {
      final pInterfaceGuid = calloc<GUID>()
        ..ref.setGUID(ppInterfaceList.value.ref.InterfaceInfo[i].InterfaceGuid
            .toString());

      const opCode = 7; // wlan_intf_opcode_current_connection
      final pdwDataSize = calloc<DWORD>();
      final ppAttributes = calloc<Pointer<WLAN_CONNECTION_ATTRIBUTES>>();

      try {
        hr = WlanQueryInterface(clientHandle, pInterfaceGuid, opCode, nullptr,
            pdwDataSize, ppAttributes.cast(), nullptr);
        if (hr != ERROR_SUCCESS) break;
        if (ppAttributes.value.ref.isState != 0) {
          return query(pInterfaceGuid, ppAttributes.value);
        }
      } finally {
        free(pInterfaceGuid);
        free(pdwDataSize);
        if (ppAttributes.value != nullptr) {
          WlanFreeMemory(ppAttributes.value);
        }
        free(ppAttributes);
      }
    }
    return null;
  } finally {
    WlanFreeMemory(ppInterfaceList);
    closeHandle();
  }
}