【问题标题】:How to get mac address如何获取mac地址
【发布时间】:2022-03-28 15:17:17
【问题描述】:

我正在开发一个在 hololens2 上运行的 uwp 应用,我想获取 wifi mac 地址。

根据这个文件:Windows.Networking,我写了这段代码。

 // part of includes at pch.h
 #include <winrt/Windows.ApplicationModel.Activation.h>
 #include <winrt/Windows.ApplicationModel.Core.h>
 #include <winrt/Windows.Foundation.h>
 #include <winrt/Windows.Foundation.Collections.h>
 #include <winrt/Windows.Foundation.Metadata.h>
 #include <winrt/Windows.Data.Xml.Dom.h>
 #include <winrt/Windows.Devices.h>
 #include <winrt/Windows.Devices.WiFi.h>
 #include <winrt/Windows.Devices.WiFiDirect.h>
 #include <winrt/Windows.Devices.Sms.h>
 #include <winrt/Windows.Networking.h>
 #include <winrt/Windows.Networking.BackgroundTransfer.h>
 #include <winrt/Windows.Networking.Connectivity.h>
 #include <winrt/Windows.Networking.NetworkOperators.h>
 #include <winrt/Windows.Networking.Proximity.h>
 #include <winrt/Windows.Networking.PushNotifications.h>
 #include <winrt/Windows.Networking.ServiceDiscovery.Dnssd.h>
 #include <winrt/Windows.Networking.Sockets.h>
 #include <winrt/Windows.Networking.Vpn.h>
 // some cpp function
    
     void MainPage::ClickLoginHandler(IInspectable const&, RoutedEventArgs const&)
     {
         using namespace winrt::Windows::Foundation::Collections;
         using namespace winrt::Windows::Networking;
         using namespace winrt::Windows::Networking::Connectivity;
         using namespace winrt::Windows::Networking::NetworkOperators;
         ConnectionProfile profile = NetworkInformation::GetInternetConnectionProfile();
         NetworkOperatorTetheringManager manager = 
NetworkOperatorTetheringManager::CreateFromConnectionProfile(profile); // error on the line
         IVectorView<NetworkOperatorTetheringClient> clients = manager.GetTetheringClients();
         for (NetworkOperatorTetheringClient client : clients)
         {
             OutputDebugString(client.MacAddress().c_str());
             OutputDebugString(L"\r\n");
         }
     }

但是却报错:WinRT origin error - 0x8007007F : 'The specified procedure could not be found.'。

似乎缺少dll,我找不到哪一个或两个?

如果你知道,请告诉我。

如果你知道其他获取mac地址的方法,请告诉我。

谢谢

【问题讨论】:

  • 从文档派生它看起来需要添加wiFiControl 功能。你启用了吗?
  • 是的,我在Package.appxmanifest中添加了它,或者报告访问被拒绝,不同的情况。@NicoZhu-MSFT
  • 你在桌面上测试过吗?是否只出现在 hololens2 设备中?
  • 也许吧。我会测试。但我最终必须在 hololens2 中获得 mac。
  • 当然,只要转换就行了。

标签: c++ uwp hololens cppwinrt


【解决方案1】:

如何获取hololens2的mac地址。

对于这种情况,你可以使用GetAdaptersAddresses 方法来接近。该文档有simple code,您可以参考。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    相关资源
    最近更新 更多