-
Apr 6th, 2024, 07:47 AM
#1
[VB6, twinBASIC] Code snippet: Toggle airplane mode
Newer versions of Windows have an 'Airplane mode' toggle like cell phones that turns off all the radios, which on a desktop might only be WiFi, but if you have a Surface tablet would also Bluetooth and possibly 4G. Microsoft doesn't really like you interacting with these yourself; it documents interfaces like IRadioInstance; but only for radio providers-- it doesn't disclose how you might go about obtaining them as a consumer to toggle them on your own.
Airplane mode is even more opaque. Disabling all the radios individually isn't enough for the little airplane to show up and the Settings indicate Airplane Mode is on. Turns out they have a very simple COM object to turn it on and off, but it's completely undocumented. user3296587 on StackOverflow reverse engineered it and posted some C++ code, which I first brought to twinBASIC and now to VB6 in the latest release of oleexp. VB6/tB of course make using COM interfaces a breeze, so toggling airplane mode is just a few simple lines:
Code:
Dim pRM As New RadioManagementAPI
Dim pbOld As Long, arg2 As Long, arg3 As Long
pRM.GetSystemRadioState pbOld, arg2, arg2
pRM.SetSystemRadioState IIf(pbOld, 0, 1)
Note this is retrieving whether any radio are active, so Airplane Mode is Enabled when pbOld is 0. See 'Interacting with individual radios' after the requirements for the app in the screenshot with the GUI for switching it on/off.
Requirements
VB6: A reference to oleexp.tlb, v6.5 or higher. IDE only, not needed for compiled exe.
twinBASIC: oleexp.tlb is 32bit only, so while you can use it, it's better to use Windows Development Library for twinBASIC (WinDevLib) which also supports 64bit and covers 100% of oleexp.tlb (+5500 more APIs). Added via the Package Manager (details).
Interacting with individual radios
If you want to list, query, and toggle system radios on an individual basis, check out my full RadioMan project. It's only for twinBASIC right now but would be trivial to port to VB6; oleexp has all the required interfaces. It's also very small thanks to these high level interfaces; the whole thing is under 500 lines (excluding the interface defs in WinDevLib/oleexp).
-
Apr 7th, 2024, 04:22 AM
#2
Re: [VB6, twinBASIC] Code snippet: Toggle airplane mode
Very good. I could find that quite useful.
I have some old semaphore indicator widgets that work (indicate) and can operate some system function via a switch. I've wanted to find a specific use for these in conjunction with VB6.
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Apr 7th, 2024, 04:29 AM
#3
Re: [VB6, twinBASIC] Code snippet: Toggle airplane mode
I love all your settings apps by the way. It would be fun to steampunk each and every one of them.
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|