I am going to put an network status icon in my GUI application. To get the network status notification, I am trying to use the Windows API. For this I am thinking to use NetworkAvailabilityChangedEventHandler in my application. I am very new to programming with the Windows API and framework. Can anybody help me in the following things:
- Can the API
NetworkAvailabilityChangedEventHandleonly be used in C#? - Can I use it in C++ (Qt)?
- Which header file must I include? (I checked in MSDN for this. but they are using namespace for this. All the examples are in C#. I am not able to understand how to implement it in my C++ code.)
I will be grateful if somebody can give me a detailed code snippet for using this windows event handler, including the .h file or namespace to be included.
Where did you get the idea to use the
NetworkAvailabilityChangedEventHandlerdelegate?That is explicitly not part of the Windows API, but rather a delegate function used by the .NET Framework in conjunction with the
NetworkChange.NetworkAvailabilityChangedevent. That explains why all the examples on MSDN are in C#—because this is only intended to be used in applications targeting the .NET Framework. If you’re writing unmanaged C++ using Qt, then you’re not using the .NET Framework, and you can’t take advantage of its functionality.The Windows API equivalent is the
InternetGetConnectedStatefunction, which returns a value indicating whether or not the system is currently connected to the Internet. You’ll find that its MSDN documentation is substantially friendlier towards unmanaged C++ developers, because that’s theprimary intended audience. The information that you’re seeking is given at the bottom:
You can find a list of all the WinINet functions here.