# SetSystemPowerState returns error code 2 with POWER_STATE_IDLE on Windows Embedded CE 6.0?

### Question

• Hi all,

Error code 2 returns when I call the function SetSystemPowerState with POWER_STATE_IDLE. There is only SYSGEN_PM catalog item on Windows Embedded CE 6.0 (not-existance SYSGEN_PM_PDA). I've modified sources.pm as the following then started "Clean Sysgen". But OS still uses the default PM module.

TARGETNAME=pm

RELEASETYPE=PLATFORM
SYNCHRONIZE_DRAIN=1

DLLENTRY=_DllEntryCRTStartup

DEFFILE=$(_PUBLICROOT)\common\oak\inc\pm.def SOURCELIBS=\$(_PUBLICROOT)\common\oak\lib\$(_CPUINDPATH)\pm_pda_pdd_lib \$(_PUBLICROOT)\common\oak\lib\$(_CPUINDPATH)\pm_mdd_lib.lib \$(_PUBLICROOT)\common\oak\lib\$(_CPUINDPATH)\pm_pdd_common_lib.lib TARGETLIBS=\$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib SOURCES= I suppose PM_PM_PDA_PDD should be active. Which settings should I make in order to use SetSystemPowerState with POWER_STATE_IDLE successfully? Thanks a lot for your helps and clarifications, Yasemin Tuesday, August 23, 2011 3:46 PM ### Answers • To use the sysgen variable you would have needed to perform a Clean Sysgen for that environment variable to be picked up, not just a build bsp and sub-projects. Also look at http://nicolasbesson.blogspot.com/2008/04/power-management-under-window-ce-part.html as it explains the power management in wince. And look at http://www.e-consystems.com/blog/windowsce/?p=229 as it explains how to customize it. I cloned the complete module, the dll, mdd and pdd sections. To add a new state you need to add a registry entry to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\State] with the name of the state you want. You need to add a class to pwstates.cpp that reports the same string that you have entered in the registry, including adding it to the initialiser at the bottom of the file.And you need to add the state to the platform_activity_state enum. There is also a flag that allows a user to set the system into the specific state, so if you are calling it from an application you need to return true to AppsCanRequestState(). I have a dll directory with the following sources file: _ISVINCPATH=$(_WINCEROOT)\public\common\sdk\inc;$(_WINCEROOT)\public\common\oak\inc; _OEMINCPATH=$(_WINCEROOT)\public\common\ddk\inc;$(_WINCEROOT)\public\common\oak\inc;$(_WINCEROOT)\public\common\sdk\inc;

TARGETNAME=pm

RELEASETYPE=LOCAL
WINCEOEM=1
SYNCHRONIZE_DRAIN=1

DLLENTRY=_DllEntryCRTStartup

DEFFILE=$(_PUBLICROOT)\common\oak\inc\pm.def SOURCELIBS=\$(_TARGETPLATROOT)\lib\$(_CPUDEPPATH)\pm_default_pdd_lib.lib \$(_TARGETPLATROOT)\lib\$(_CPUDEPPATH)\pm_mdd_lib.lib \$(_TARGETPLATROOT)\lib\$(_CPUDEPPATH)\pm_pdd_common_lib.lib \ TARGETLIBS=\$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib \$(_SYSGENOAKROOT)\lib\$(_CPUINDPATH)\ceddk.lib \ And in the other sources files I made the RELEASETYPE=PLATFORM. The directory structure looks like: PM-> DLL MDD PDD-> COMMON DEFAULT with a sources.cmn in the PM directory that contains: _ISVINCPATH=$(_WINCEROOT)\public\common\sdk\inc;
_OEMINCPATH=$(_WINCEROOT)\public\common\ddk\inc;$(_WINCEROOT)\public\common\oak\inc;$(_WINCEROOT)\public\common\sdk\inc; RELEASETYPE=PLATFORM WINCEOEM=1 TARGETLIBS=\$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib SOURCES= • Marked as answer by Tuesday, September 06, 2011 5:51 AM Thursday, August 25, 2011 1:28 AM ### All replies • I found that I needed to clone the pm module to modify the power states as I was adding more states than in the default or pda states, I wouldn't be modifying the public code. To add the pda pm component I think you just need to add the SYSGEN_PM_PDA to your environment variables. Wednesday, August 24, 2011 12:36 AM • Hi Barak14, I tried to add SYSGEN_PM_PDA to the environment variables then built with "Build Current BSP and Subprojects". But it still uses the default pm pdd. So I decide to clone the PM module. I have cloned the NETUI module successfully before. But PM has a bit complexity for me because it has MDD/PDD parts. Could you please give me some tips/helpful sources in order to succeed it? Thanks a lot, Wednesday, August 24, 2011 6:15 AM • I've cloned the PM module by implementing the list below. Now I want to add a power state like SystemIdle to be called with SetSystemPowerState(POWER_STATE_IDLE). I can't understand completely the relationship between the registry [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\State] and PM_PDD source. How to add a new system power state? -- Created a folder named "PM" under OSDesign project. -- Copied the content of C:\WINCE600\PUBLIC\COMMON\OAK\DRIVERS\PM\PDD\PDA to OSDesign PM folder. -- Modified the sources file of OSDesign PM as following: _ISVINCPATH=$(_WINCEROOT)\public\common\sdk\inc;
_OEMINCPATH=$(_WINCEROOT)\public\common\ddk\inc;$(_WINCEROOT)\public\common\oak\inc;$(_WINCEROOT)\public\common\sdk\inc; WINCEOEM=1 WINCEREL=1 TARGETNAME=pm TARGETTYPE=DYNLINK RELEASETYPE=LOCAL DLLENTRY=DllEntry DEFFILE=$(TARGETDEFNAME).def

SOURCELIBS=\
$(_PROJECTROOT)\cesysgen\oak\lib\$(_CPUINDPATH)\pm_mdd_lib.lib \
$(_PROJECTROOT)\cesysgen\oak\lib\$(_CPUINDPATH)\pm_pdd_common_lib.lib

TARGETLIBS=\
$(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\coredll.lib

SOURCES = \
platform.cpp \
pwstates.cpp

-- Inserted to OSDesign project using "Add Existing Subproject..." through sources file.

-- Uncomment the line in pm.bib.

-- Build.

Thanks a lot,

Wednesday, August 24, 2011 7:11 AM
• To use the sysgen variable you would have needed to perform a Clean Sysgen for that environment variable to be picked up, not just a build bsp and sub-projects.

Also look at http://nicolasbesson.blogspot.com/2008/04/power-management-under-window-ce-part.html as it explains the power management in wince.

And look at http://www.e-consystems.com/blog/windowsce/?p=229 as it explains how to customize it.

I cloned the complete module, the dll, mdd and pdd sections. To add a new state you need to add a registry entry to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\State] with the name of the state you want. You need to add a class to pwstates.cpp that reports the same string that you have entered in the registry, including adding it to the initialiser at the bottom of the file.And you need to add the state to the platform_activity_state enum. There is also a flag that allows a user to set the system into the specific state, so if you are calling it from an application you need to return true to AppsCanRequestState().

I have a dll directory with the following sources file:

_ISVINCPATH=$(_WINCEROOT)\public\common\sdk\inc;$(_WINCEROOT)\public\common\oak\inc;
_OEMINCPATH=$(_WINCEROOT)\public\common\ddk\inc;$(_WINCEROOT)\public\common\oak\inc;$(_WINCEROOT)\public\common\sdk\inc; TARGETNAME=pm TARGETTYPE=DYNLINK RELEASETYPE=LOCAL WINCEOEM=1 SYNCHRONIZE_DRAIN=1 DLLENTRY=_DllEntryCRTStartup DEFFILE=$(_PUBLICROOT)\common\oak\inc\pm.def

SOURCELIBS=\
$(_TARGETPLATROOT)\lib\$(_CPUDEPPATH)\pm_default_pdd_lib.lib \
$(_TARGETPLATROOT)\lib\$(_CPUDEPPATH)\pm_mdd_lib.lib \
$(_TARGETPLATROOT)\lib\$(_CPUDEPPATH)\pm_pdd_common_lib.lib \

TARGETLIBS=\
$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib \
$(_SYSGENOAKROOT)\lib\$(_CPUINDPATH)\ceddk.lib \

And in the other sources files I made the RELEASETYPE=PLATFORM.

The directory structure looks like:

PM->

DLL

MDD

PDD->

COMMON

DEFAULT

with a sources.cmn in the PM directory that contains:

_ISVINCPATH=$(_WINCEROOT)\public\common\sdk\inc; _OEMINCPATH=$(_WINCEROOT)\public\common\ddk\inc;$(_WINCEROOT)\public\common\oak\inc;$(_WINCEROOT)\public\common\sdk\inc;

RELEASETYPE=PLATFORM
WINCEOEM=1

TARGETLIBS=\
$(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib

SOURCES=

• Marked as answer by Tuesday, September 06, 2011 5:51 AM
Thursday, August 25, 2011 1:28 AM
• Thanks so much to you!
Tuesday, September 06, 2011 5:52 AM