Delphi XE8 - собственный API Wifi - Wlan API - получить значение от WLAN_HOSTED_NETWORK_REASON - PullRequest
0 голосов
/ 11 октября 2019

Delphi XE8 в Windows 10 Pro

Так что я использую WlanHostedNetworkStartUsing из Native Wifi API для запуска Hosted Network, используя этот код:

procedure TForm1.btn_1Click(Sender: TObject);
var
  hClient              : THandle;
  dwVersion            : DWORD;
  Result               : DWORD;
  pReason              : Pndu_WLAN_HOSTED_NETWORK_REASON;
  pStatus              : Pndu_WLAN_HOSTED_NETWORK_STATUS;
begin
  if btn_1.Caption = 'start' then
  begin
    Result :=WlanOpenHandle(1, nil, @dwVersion, @hClient);
    if  Result <> ERROR_SUCCESS then
    begin
       ShowMessage(IntToStr(Result));
       Exit;
    end;

    Result:=WlanHostedNetworkStartUsing(hClient,@pReason, nil);
    if  Result <> ERROR_SUCCESS then
    begin
       ShowMessage(IntToStr(Result));
    end else
    begin
      btn_1.Caption := 'stop';
      ShowMessage(HNSToString(pReason^)); // << Im not sure what i am doing with this
    end;
  end else
  begin
    Result:=WlanOpenHandle(1, nil, @dwVersion, @hClient);
    if  Result <> ERROR_SUCCESS then
    begin
       ShowMessage(IntToStr(Result));
       Exit;
    end;

    Result:=WlanHostedNetworkForceStop(hClient,@pReason, nil);
    if  Result <> ERROR_SUCCESS then
    begin
       ShowMessage(IntToStr(Result));
    end else
    begin
      btn_1.Caption := 'start';
    end;
  end;
end;

Затем я объявляю этофункция для преобразования pReason значения в строку:

function TForm1.HNSToString(reason: Tndu_WLAN_HOSTED_NETWORK_REASON): string;
begin
Result := '';
  case reason of
    wlan_hosted_network_reason_success : Result := 'Success';
    wlan_hosted_network_reason_unspecified : Result := 'Unspecified';
    wlan_hosted_network_reason_bad_parameters : Result := 'Bad Parameters';
    wlan_hosted_network_reason_service_shutting_down : Result := 'Service Shutting Down';
    wlan_hosted_network_reason_insufficient_resources : Result := 'Inssuficient Resources';
    wlan_hosted_network_reason_elevation_required : Result := 'Elevation Required';
    wlan_hosted_network_reason_read_only : Result := 'Read Only';
    wlan_hosted_network_reason_persistence_failed : Result := 'Persistance Failed';
    wlan_hosted_network_reason_crypt_error : Result := 'Crypt Error';
    wlan_hosted_network_reason_impersonation : Result := 'Impersonation';
    wlan_hosted_network_reason_stop_before_start : Result := 'Stop Before Start';
    wlan_hosted_network_reason_interface_available : Result := 'Interface Available';
    wlan_hosted_network_reason_interface_unavailable : Result := 'Interface Unavailable';
    wlan_hosted_network_reason_miniport_stopped : Result := 'Miniport Stopped';
    wlan_hosted_network_reason_miniport_started : Result := 'Miniport Started';
    wlan_hosted_network_reason_incompatible_connection_started : Result := 'Incompatible Connection Started';
    wlan_hosted_network_reason_incompatible_connection_stopped : Result := 'Incompatible Connection Stopped';
    wlan_hosted_network_reason_user_action : Result := 'User Action';
    wlan_hosted_network_reason_client_abort : Result := 'Client Abort';
    wlan_hosted_network_reason_ap_start_failed : Result := 'AP Start Failed';
    wlan_hosted_network_reason_peer_arrived : Result := 'Peer Arrived';
    wlan_hosted_network_reason_peer_departed : Result := 'Peer Departed';
    wlan_hosted_network_reason_peer_timeout : Result := 'Peer Timeout';
    wlan_hosted_network_reason_gp_denied : Result := 'GP Denied';
    wlan_hosted_network_reason_service_unavailable : Result := 'Service Unavailable';
    wlan_hosted_network_reason_device_change : Result := 'Device Change';
    wlan_hosted_network_reason_properties_change : Result := 'Properties Change';
    wlan_hosted_network_reason_virtual_station_blocking_use : Result := 'Virtual Station Blocking Use';
    wlan_hosted_network_reason_service_available_on_virtual_station : Result := 'Service Available On Virtual Station';
  end;
end;

Но я получаю Нарушение доступа blabla при использовании кода выше

Возможно ли получитьцелочисленное или строковое значение из WLAN_HOSTED_NETWORK_REASON?

https://docs.microsoft.com/en-us/windows/win32/api/wlanapi/nf-wlanapi-wlanhostednetworkstartusing

https://docs.microsoft.com/en-us/windows/win32/api/wlanapi/ne-wlanapi-wlan_hosted_network_reason

https://github.com/coolshou/WlanAPI

Заранее спасибо: D

...