开发者

How do I use the windows network API in Qt?

开发者 https://www.devze.com 2023-02-09 04:11 出处:网络
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 NetworkAvaila

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消