vla*_*378 5 c++ winapi wifi windows-10
我正在尝试编写一个创建热点的程序.我正在使用,WlanHostedNetworkStartUsing但它返回ERROR_INVALID_STATE.然而,当我打电话给WlanHostedNetworkInitSettings它时,返回succsess.根据文档(备注部分的最后一段),它应该在控制面板\网络和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
/ ...
Run Code Online (Sandbox Code Playgroud)
所以它说我的wifi适配器根本没有wifi共享(我有HP网站的最后一个驱动程序).
但是,当我尝试使用Windows 10内置工具创建热点时,它可以工作.

问题:Windows工具如何做到这一点以及如何在我的应用程序中使用此机制?
2018 年 6 月 6 日的原始评论在这里(请参阅下面的更新):
Microsoft 弃用了 WLAN HostedNetwork 功能,它不适用于 Win10 驱动程序。要在 Win10 中使用旧模型,您必须找到并安装 2015(8.1 或更早版本,具体取决于供应商)的驱动程序。
Win10 驱动程序模型将 HostedNetwork 的机制更改为基于 WiFi Direct,并从应用程序开发人员手中夺走控制权并将此功能移至内核。如果您深入了解,可以使用一些示例,这些示例展示了如何使用 Modern-com (RT) UWP 应用程序库来配置 WiFi Direct HostedNetwork。这是一个 PITA,微软没有解释,大多数在网络上对此发表评论的人都不理解,而且这看起来像是微软的两步失败,其中产品功能被削减以制定发货计划并在其中重新组织团队更改了 WiFi 和热点的所有权和计划。WiFi 直连在理论上实现了设备之间更简单的配对和身份验证模型。但是目前的实现涉及蓝牙,因此除了支持有限的移动设备 WiFi 2.0 场景之外,它是有问题的。如果您正在使用无头设备或 IoT 设备方案,这将被破坏。
我不得不在这方面做很多工作。如果您可以选择 WiFi 硬件,我强烈推荐使用 Intel 驱动程序的硬件芯片组(它们是可靠的)。
如果您的场景允许 UX 交互,您可能会发现此 App Store 应用程序很有帮助。 http://www.topuwp.com/windowsapps/wifi-direct-access-point/598084.html
====================
02/27/2020 更新那个故事......
当Hosted network supported : No那么传统 托管的网络支持不可用在适配器上,因为你有wifi直在Windows 10等。你要知道,用这种这种情况下,很稀疏评论wifi直连支持的一部分:
HotSpot 设置的命令行: start ms-settings:network-mobilehotspot
讨论 PowerShell 以编程方式访问 WinRT HotSpot API 的文章
通过 cmd/batch/powershell 启用 Win10 内置热点
关键词:“虚拟 Wi-Fi”、SoftAP、AdHoc IBSS、MobileHotSpot、netsh wlan HostedNetwork
====================
如果没有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();
}
}
Run Code Online (Sandbox Code Playgroud)
在此处查找与以下内容相关的旧 Microsoft 示例WiFiDirectAdvertisementPublisher:
WFD_GROUP_OWNER_PROFILE配置文件位于以下目录路径中:C:\ProgramData\Microsoft\Wlansvc\Profiles\Interfaces\网络上的文章太多了,WiFi-Direct 造成了太多的混乱。
我花了整整两天的时间才弄清楚。就我而言,这是很多。
微软(我曾经在那里担任架构师)没有任何借口没有创建一个关于这个非常受欢迎的主题的博客。更不用说简单地提供netsh和Ad Hoc Wifi兼容支持,而不是让DevOps、最终用户和开发人员如此神秘和困惑。
——享受 大卫
以上内容非常简洁,并公开了适用于所有场景的 C++/WinRT 代码。
[我现在在 EdgeS 中捆绑了这个:EdgeShell/EdgeScript/afm-scm 工具集] [
] 5
小智 -2
以管理员身份打开命令提示符并尝试以下命令:
\n\nnetsh wlan set hostednetwork mode=allow ssid=\xe2\x80\x9cOSToto Hotspot\xe2\x80\x9d key=\xe2\x80\x9c12345678\xe2\x80\x9d\nRun Code Online (Sandbox Code Playgroud)\n\nssid 是您的网络名称,密钥是密码。您可以像上面的命令一样命名它们。
\n\n然后运行:
\n\nnetsh wlan start hostednetwork\nRun Code Online (Sandbox Code Playgroud)\n\n先休息一下再说,我想看一下你的源代码。
\n| 归档时间: |
|
| 查看次数: |
920 次 |
| 最近记录: |