Toggle WiFi/BT/Phone using .NET code only!!!

Search This thread

amaric

Senior Member
Dec 16, 2007
149
12
Hi people,

A little something primary for .NET developers but native developers can benefit from this too.

Maybe you were working really hard to make google find you a .NET code to toggle radio devices. I know I did and i was unsuccessful.

Maybe you found some sites about ossvcs.dll and undocumented functions for controlling the Radio Devices. But you were just missing that last piece - .NET code that calls them without some intermediate c++ dll.

Your search is over because i give you my .NET CF code that you can use to toggle WiFi/Bluetooth/Phone by using PInvoke of undocumented functions in mentioned ossvcs.dll!

This is a general solution, so it should work on all devices (I tried it on old ipaq 1940, Qtek 8310 and HTC s730)!

DllImports :

[DllImport("ossvcs.dll", EntryPoint = "#276")]
internal static extern int GetWirelessDevices(ref IntPtr pDevices, int dwFlags);

[DllImport("ossvcs.dll", EntryPoint = "#280")]
internal static extern int FreeDevicesList(IntPtr pDevices);

[DllImport("ossvcs.dll", EntryPoint = "#273")]
internal static extern int ChangeRadioState(IntPtr pDevices, int dwState, SAVEACTION sa);


In the attachement you will find code for 3 projects :
- RadioManager (real code is here)
- RadioManagerTester (Forms application for testing)
- RadioMngrCnsl (Console application for users)


If you have any questions feel free to post them here.

If you want to show your support for my work and encourage me to continue posting code like this you can do that by donating through
Just send me a PM and i'll tell you my e-mail address.
 

Attachments

  • RadioManager.zip
    85.3 KB · Views: 1,871

APBilbo

Senior Member
Aug 28, 2007
1,453
10
Madrid
Hi!


Thanks for sharing your code... I pitty you didn't do it a week ago :(, hehehe... I found a really close solution but I've tried your's as it seems better structured ;). Although the wifi doesn't work on my device for some reason (HTC Herald). By mixing your solution and mine it does work. Here you've the code:

Code:
        [DllImport("coredll.dll", SetLastError = true)]
        public static extern int DevicePowerNotify(string name, CEDEVICE_POWER_STATE state, int flags);

        public void SwitchWifiState()
        {
            rdm = new RadioDeviceManager();
            rdm.Dispose();
        }
        private void _WiffiToggle(String name)
        {
            CEDEVICE_POWER_STATE cps = Microsoft.WindowsMobile.Status.SystemState.WiFiStatePowerOn ? 4 : 0;
            DevicePowerNotify(name, cps, 1);
        }

In case you find some one with the same problem you can give this a try ;).

Thanks again for your share!!
 

amaric

Senior Member
Dec 16, 2007
149
12
Hmmm....i was using that solution with DevicePowerNotify but then i had a lot of problem with comm manager. If I turn on device with this i can't turn it off with comm manager. And if i turn it off i can't turn it on with comm manager (on Qtek 8310).

Anyway, does RefreshDevicesList iin RadioDeviceManager class returns RDD structure for your radio device? Can you toggle bluetooth or phone?
 

APBilbo

Senior Member
Aug 28, 2007
1,453
10
Madrid
Hmmm....i was using that solution with DevicePowerNotify but then i had a lot of problem with comm manager. If I turn on device with this i can't turn it off with comm manager. And if i turn it off i can't turn it on with comm manager (on Qtek 8310).

Anyway, does RefreshDevicesList iin RadioDeviceManager class returns RDD structure for your radio device? Can you toggle bluetooth or phone?

On my devie there are no such problems... Strange....

Your code detects my wifi perfectly and toggles BT and Phone... It just doesn't work with Wifi... No error is thrown...
 

jrsenthilk

New member
Jan 16, 2009
1
0
no devices found

hi,
i am quite new to .NET programming... i have been using c++ all this while.. I tried your code on my windows mobile 6.0 professional product.. but unfortunately i keep getting "Devices not found" message..
Is there any issue that i have not taken care of..
thank you very much for any help..
thanks for your code too....

regards,
Senthil.K
 
Last edited:
wifi

am devloping a WM 6 app in VB.net (2005)

ok i have the bluetooth bit sorted and working fine.

However I can't get the wifi bit working.
It appears not to be able to find the correct device to change the power on

I also can't open the example code as its in a different VS version. :(


Any ideas?

Thanks
 

romanini

New member
Feb 12, 2009
1
0
Hello everyone,
sorry for not being so professional, but I figured out that manually changing the following registry keys it makes the job done even though the 'Comm Manager' doesn't realize the wifi has turned off.

Any recommendation not for doing so?


HKEY_LOCAL_MACHINE\System\State\Hardware\Wifi (5 disabled, 23 enabled)
HKEY_LOCAL_MACHINE\Software\Drivers\WLAN\WlanStatus (0 disabled, 1 enabled)

(using HTC Touch HD)


Have a nice day.