Dec 2, 2009

Wifi (wlan) is off when the power-off button is pressed

Today I've just found the way to prevent wlan (wifi) on Window Mobile from being off after the power button is pressed (in order to turn off the pocket pc's screen).

The solution is very simple; We just switch on the "Unattended" PowerPolicy.

In order to set the PowerPolicy, we use:

[PreserveSig]
[DllImport("coredll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Ansi)]
public static extern bool PowerPolicyNotify(PowerManager.PPN_Message dwMessage, int dwData);


Then to switch on the "Unattended" PowerPolicy, we invoke:

PowerPolicyNotify(3, 1);

  • The first parameter is the PowerPolicy's identification and 3 is for the "unattended" PowerPolicy.
  • The second parameter is either 1(on) or 0(off).


You also need to keep sending package every 10 or 20 seconds to keep the wifi active.

And that is it. When you press the power button to turn off the screen, the wifi won't go offline anymore. Try it!


PS. I have tried with Symbol MC50 (Window Mobile 5)

---------------------------------------------------------

* After beta-testing, we have found that WiFi still goes off around every hour.

We have to turn WiFi on programmatically, if that is the case.

Here is the code :

[PreserveSig]
[DllImport("Coredll.dll")]
public static extern int SetDevicePower(string device, int dwDeviceFlags, int state);

[PreserveSig]
[DllImport("Coredll.dll")]
public static extern int DevicePowerNotify(string device, int state, int flags);


DevicePowerNotify("wlp1:", 0,1);
SetDevicePower("wlp1:", 1, 0);

* WiFi device for Symbol MC50 is named "wlp1:"