gpt4 book ai didi

c++ - WlanHostedNetworkStartUsing 或 Windows 10 内置移动热点的工作原理

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:38:02 26 4
gpt4 key购买 nike

我正在尝试编写一个创建热点的程序。我正在使用 WlanHostedNetworkStartUsing 但它返回 ERROR_INVALID_STATE。然而,当我调用 WlanHostedNetworkInitSettings 时,它返回成功。根据documemtation (备注 部分的最后一段)它应该在控制面板\网络和 Internet\网络和共享中心 下创建虚拟无线连接,但它没有。

我搜索了一下,发现了这个:

当我运行 netsh wlan show drivers 时,它显示:

Driver                    : Intel(R) Dual Band Wireless-AC 3165
Vendor : Intel Corporation
Provider : Intel
Date : 07-Sep-16
Version : 19.20.0.6
INF file : ????
Type : Native Wi-Fi Driver
Radio types supported : 802.11b 802.11g 802.11n 802.11a 802.11ac
/ ...
Hosted network supported : No <--- Here
/ ...

所以它说我的 wifi 适配器根本不共享 wifi(我有来自 HP 网站的最新驱动程序)。

但是,当我尝试使用 Windows 10 内置工具创建热点时,有效Windows tool sample

问题:Windows 工具如何做到这一点以及我如何在我的应用程序中使用这种机制?

最佳答案

Original 06/06/2018 comments here (see updates below):

Microsoft deprecated the WLAN HostedNetwork capability and it is NOT available for Win10 drivers. To use the old model in Win10 you must find and install drivers from 2015 (8.1 or possibly earlier depending on vendor).

The Win10 driver model changed the mechanism of HostedNetwork to be based on WiFi Direct, and took control away from app-developers and moved this feature to the kernel. There are some samples available if you dig around, that show how to use the modern-com (RT) UWP app libraries to configure a WiFi Direct HostedNetwork. It is a PITA, which was not explained by Microsoft, is not understood by most people commenting on this in the web, and which mostly looks like a two-step microsoft failure where product features were cut to make ship schedule and re-orgs among teams changed the ownership and plan for WiFi and hotspots. WiFi direct enables - theoretically - a simpler pairing and authentication model between devices. But the currently implementation involves bluetooth and therefore it is questionable other than support a limited mobile device WiFi 2.0 scenario. If you are working with headless devices or IoT device scenarios this is broken.

I've had to do a lot of work in this area. If you have a choice in WiFi hardware, I strongly recommend a hardware chipset that uses the Intel drivers (they are solid).

You may find this App store app helpful if your scenario allows for UX interaction. http://www.topuwp.com/windowsapps/wifi-direct-access-point/598084.html

====================

02/27/2020 更新该故事...

托管网络支持:否 时,传统 托管网络 支持在您的适配器上不可用,因为您在 Windows 10 等中有 WiFi Direct . 在这种情况下,您会想知道并使用这个很少评论的 WiFi Direct 支持部分:

https://learn.microsoft.com/en-us/uwp/api/windows.networking.networkoperators.networkoperatortetheringmanager.createfromconnectionprofile

HotSpot 设置的命令行:start ms-settings:network-mobilehotspot

讨论 PowerShell 以编程方式访问 WinRT HotSpot API 的文章

enable Win10 inbuild hotspot by cmd/batch/powershell

关键词:“虚拟 Wi-Fi”、SoftAP、AdHoc IBSS、MobileHotSpot、netsh wlan 托管网络

====================

如果没有有效的 C++/WinRT 代码示例,这将是不完整的,如下所示:

#include <winrt/Windows.Networking.Connectivity.h>
#include <winrt/Windows.Networking.NetworkOperators.h>
#include <winrt/Windows.Devices.WiFiDirect.h>
#include <winrt/Windows.Security.Credentials.h>
namespace winrt { // /ZW embed in :<winrt> when `Windows` is ambiguously defined
static void af_winrt_wifi_hotspot_test() {
// start ms-settings:network-mobilehotspot
init_apartment(); // apartment_type::multi_threaded
if (false /* play as you wish to test this all in simple c++ console app, I used clang */) {
auto publisher = Windows::Devices::WiFiDirect::WiFiDirectAdvertisementPublisher();
auto advertisement = publisher.Advertisement();
advertisement.ListenStateDiscoverability(Windows::Devices::WiFiDirect::WiFiDirectAdvertisementListenStateDiscoverability::Intensive);
advertisement.IsAutonomousGroupOwnerEnabled(true);
auto legacySettings = advertisement.LegacySettings();
legacySettings.IsEnabled(true);
legacySettings.Ssid(L"your-hotspot-name");
auto credential = Windows::Security::Credentials::PasswordCredential(); credential.Password(L"the-password!");
legacySettings.Passphrase(credential);
publisher.Start();
}
else {
auto connectionProfile{ Windows::Networking::Connectivity::NetworkInformation::GetInternetConnectionProfile() };
auto tetheringManager = Windows::Networking::NetworkOperators::NetworkOperatorTetheringManager::CreateFromConnectionProfile(connectionProfile);
auto credential = Windows::Security::Credentials::PasswordCredential(); credential.Password(L"the-password!");
auto conf = Windows::Networking::NetworkOperators::NetworkOperatorTetheringAccessPointConfiguration();
conf.Ssid(L"I-Own-You"); conf.Passphrase(credential.Password());
auto oldConf = tetheringManager.GetCurrentAccessPointConfiguration();
auto oldSsid = oldConf.Ssid(); auto oldPwd = oldConf.Passphrase();
tetheringManager.ConfigureAccessPointAsync(conf); // Sets new ssid/pwd here
switch (tetheringManager.TetheringOperationalState()) {
case Windows::Networking::NetworkOperators::TetheringOperationalState::Off: {
auto ioAsync = tetheringManager.StartTetheringAsync();
auto fResult = ioAsync.get();
}
break;
case Windows::Networking::NetworkOperators::TetheringOperationalState::On: {
// auto ioAsync = tetheringManager.StopTetheringAsync();
// auto fResult = ioAsync.get();
}
break;
case Windows::Networking::NetworkOperators::TetheringOperationalState::InTransition:
default:
break;
}
}
clear_factory_cache();
uninit_apartment();
}
}

在此处查找与 WiFiDirectAdvertisementPublisher 相关的较早的 Microsoft 示例:

网络上有那么多文章,WiFi-Direct 造成了那么多困惑。

我花了整整两天时间才搞清楚。这对我来说已经很多了。

Microsoft(我曾在那里担任架构师)没有任何借口没有创建关于这个非常受欢迎的主题的博客。更不用说简单地提供了 netshAd Hoc Wifi 兼容支持,而不是让它对 devops、最终用户和开发人员。

-- 享受大卫

上面的内容非常简洁,并公开了适用于所有场景的有效 c++/WinRT 代码。

[我现在在 EdgeS 中捆绑了这个:EdgeShell/EdgeScript/afm-scm 工具集][ enter image description here ] 5

关于c++ - WlanHostedNetworkStartUsing 或 Windows 10 内置移动热点的工作原理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41829382/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com