0

i'm working on a uwp app runing on hololens2, i want get the wifi mac address.

according to this documents: Windows.Networking, i wrote this code.

 // 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");
         }
     }

but it reports an error: WinRT originate error - 0x8007007F : 'The specified procedure could not be found.'。

it seems missing dll, and i can not found out which one, or two?

if you know that please let me know.

if you know other way to get mac address, please let me know.

Thanks

ts_sinwh
  • 11
  • 2
  • Derive from document it looks need to add [`wiFiControl`](https://learn.microsoft.com/en-us/uwp/api/Windows.Networking.NetworkOperators.NetworkOperatorTetheringClient?redirectedfrom=MSDN&view=winrt-22000#windows-requirements) capability. Have you enabled it? – Nico Zhu Mar 01 '22 at 04:34
  • 1
    yes, i added it in Package.appxmanifest, or reports access denied, diffrent situation.@NicoZhu-MSFT – ts_sinwh Mar 01 '22 at 06:33
  • Have you tested within desktop? Does it only occur in hololens2 device? – Nico Zhu Mar 01 '22 at 06:48
  • maybe. i will test. but i have to get mac in hololens2 finally. – ts_sinwh Mar 01 '22 at 07:13
  • Well. you could also use pinvoke method GetAdaptersInfo to approach. please try this [link](https://stackoverflow.com/a/34098615/7254781). – Nico Zhu Mar 01 '22 at 07:35
  • Ok, good may I convert it as answer for this thread? – Nico Zhu Mar 03 '22 at 01:23
  • 1
    of course, just convert it. – ts_sinwh Mar 03 '22 at 01:43
  • Have you actually verified that you can call [`GetAdaptersInfo`](https://learn.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.markup.ixamlmetadataprovider) from a program targeting the UWP? It's documented to be available for *"desktop apps only"*. – IInspectable Mar 26 '22 at 06:15

1 Answers1

-1

How to get mac address for hololens2.

For this scenario, you could use GetAdaptersAddresses method to approach. The document has simple code that you could refer.

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36