1

I see that since windows8 users can set up network as a pay-per-traffic internet link, so maybe some apps will use less data traffic

But I can't find an easy to use api to determine if the current network is billed or not when developing c++ applications

Does anyone have a link to the documentation for this?

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

0

Windows::Networking::Connectivity::NetworkInformation class is what you seek.

The GetInternetConnetionProfile method on this class returns a ConnectionProfile instance. On that object, you can invoke GetConnectionCost to get the NetworkCostType enum property. There's an event you can register a callback for when the user roams between networks so you know when to query it again.

If this property is "fixed" or "variable", you're on some sort of "metered network" connection where you might not want to have your app be conservative on network usage.

With that in mind, I believe the property that sets this bit simply a property of the network adapter. And maps to the user setting buried in Windows Settings:

enter image description here

I could be mistaken, but I'm not sure if there's any well known standard by which a network or ISP advertises the metered connection property dynamically in which Windows will pick it up. I think the OEM of the device sets this toggle switch when the machine is imaged.

selbie
  • 100,020
  • 15
  • 103
  • 173
  • But this `c#` ..., not `c++`. I found only about `WCM_CONNECTION_COST_DATA` via WCM – Mister_Jesus Aug 11 '22 at 07:22
  • @Mister_Jesus - No. All Windows APIs can be invoked from C++. It's just that the documentation is slanted towards .NET style. As a matter of fact, I based my answer by looking at the C++ code my team's project uses for detecting metered networks. – selbie Aug 11 '22 at 09:32
  • @Mister_Jesus - all you have to do is click on any of those links I shared and switch the dropdown in the top right corner of the window from C# to C++. Problem solved. There doesn't appear to be a way to craft the URL to default to that. – selbie Aug 11 '22 at 09:35
  • But this is for Win10 and not 8? – Anders Aug 11 '22 at 09:36
  • @Anders - lol. No one uses Windows 8. All kidding aside, I think those APIs may have been there since Windows 8.1. I **think** I remember my team consuming them prior to Windows 10. I honestly can not remember. The winrt/uwp API will will simply throw C++ exceptions or return COM errors if not available. – selbie Aug 11 '22 at 09:40
  • I'm typing this on a Windows 8.1 tablet right now... – Anders Aug 11 '22 at 09:42
  • @Anders - time to upgrade. – selbie Aug 11 '22 at 09:43
  • This is a HP Stream 7, they don't really make this style anymore :( (How far off topic are we now?) – Anders Aug 11 '22 at 09:45
  • Well over a decade past its introduction, and Microsoft still haven't properly communicated to developers, that the Windows Runtime is a *native* platform. That's ridiculously catastrophic communication. – IInspectable Aug 11 '22 at 16:22
  • @IInspectable - LOL. – selbie Aug 11 '22 at 16:42