I'm working on the WinUI3 desktop application in C++. I was checking how we can get an event when the network to which system is connected to changes. I came across NetworkInformation.NetworkStatusChanged event. But I was not able to find any example of its implementation in C++.
NetworkStatusChangedEventHandler says it has one parameter which is IInspectable object.
i tried
static void NetworkStatusChange(winrt::Windows::Foundation::IInspectable const& sender);
But it gave this error
*\Generated Files\winrt\Windows.Networking.Connectivity.h(2213,81): error C2297: '.*': not valid as right operand has type 'const M'
Can you please help me with help me with how to implement NetworkStatusChanged event in WinUI3 C++ desktop application correctly.
Thank you.
This is how you can do it with C++/WinRT:
add this into the pch.h:
add this somewhere in your code:
If you prefer the "raw" C/C++ way, there's an example here: How to detect network change events asynchronously using c++ WinRT