简体   繁体   中英

How do I use the windows network API in Qt?

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:

  1. Can the API NetworkAvailabilityChangedEventHandle only be used in C#?
  2. Can I use it in C++ (Qt)?
  3. 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 NetworkAvailabilityChangedEventHandler delegate?

That is explicitly not part of the Windows API, but rather a delegate function used by the .NET Framework in conjunction with the NetworkChange.NetworkAvailabilityChanged event . 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 InternetGetConnectedState function , 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 the
primary intended audience. The information that you're seeking is given at the bottom:

Header Wininet.h

Library Wininet.lib

DLL Wininet.dll

You can find a list of all the WinINet functions here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM