Windows Mobile Devices and Power States

I’ve been doing some Windows Mobile development with the .NET Compact Framework recently and ran into a scenario where I needed the device to be in “full power” mode at all times with the back-light on. The device is constantly powered, so battery life is not a concern.

The obvious choice is to go into the Brightness and Power control panels and turn off the appropriate settings, but I learned that there is a way to handle this at an application level so the behavior only occurs while the application is running.

Power State

An application can force a specific power state using the SetPowerRequirement method, and release that state using the ReleasePowerRequirement method. Using P/Invoke, these methods look like the following:

public enum CEDevicePowerState
{
 D0 = 0, // Full On
 D1, // Low On
 D2, // Standby
 D3, // Sleep
 D4, // Off
}
 
[DllImport("coredll.dll", SetLastError=true)]
static extern IntPtr SetPowerRequirement(string device, CEDevicePowerState ceDevicePowerState, uint deviceFlags, IntPtr systemState, ulong stateFlags);
 
[DllImport("coredll.dll", SetLastError=true)]
static extern int ReleasePowerRequirement(IntPtr handle);

SetPowerRequirement will allow you to set a specific power state on a specific device. In my scenario, I wanted to set the back-light to full power. The name of the back-light on most (not all) Windows Mobile devices appears to be “BKL1:”. So, to set the back-light to full power (the D0 state), you would call the method as follows:

Read More