pythonCE GetSystemPowerState windows api

Thomas Heller theller at
Sat Apr 25 18:19:36 CEST 2009

lorenzo.mentaschi at schrieb:
> Hi all,
> I need to call GetSystemPowerState windows api from pythonCE, because
> I need to know if a windows ce 5 device is in sleep/off status.
> I can find this api in ctypes.windll.coredll, but I cannot figure out
> how to pass parameters to this procedure: msdn giude (
> ) speaks about 3
> parameters, of wich 2 are output: a "LPWSTR pBuffer" and a "PDWORD
> pFlags". Returned value of the call is an exit status code
> rappresenting if call succeded or failed.
> I tried to call this api in several ways, but obtained always exit
> code 87 (meaning that parameters are wrong) or 122 (meaning "pBuffer"
> variable is too small, in this case I passed None as pBuffer, since
> I'm interested only in pFlags result).
> Have you any idea? Maybe another api or way to perform this simple
> task?

Python 2.5 (release25-maint, Dec 19 2006, 23:22:00) [MSC v.1201 32 bit (ARM)] on win32
>>> from ctypes import *
>>> d=windll.coredll
>>> d.GetSystemPowerState
<_FuncPtr object at 0x0016EC60>
>>> p=create_unicode_buffer(256)
>>> flags=c_ulong()
>>> f=d.GetSystemPowerState
>>> f(p,256,byref(flags))
>>> p.value
>>> flags
>>> hex(flags.value)


More information about the Python-list mailing list