Windows SetLocalTime
Rob Williscroft
rtw at freenet.co.uk
Wed Dec 13 16:42:20 EST 2006
Podi wrote in news:1166041988.571906.244570 at j72g2000cwa.googlegroups.com in
comp.lang.python:
> Rob Williscroft wrote:
>>
>> Google will usually find the documentation of anything in the
>> Windows API however sometimes it also helps to add "msdn" to
>> your search as in:
> Yes, thank you.
>
> I found the function SetLocalTime or SetSystemTime to set the time from
> MSDN http://msdn2.microsoft.com/en-us/library/ms724942.aspx. I am
> having trouble passing parameter to the functions in Python.
>
Ok I see, you will probably need these 2 bits of the ctypes
documentation:
http://docs.python.org/lib/ctypes-structures-unions.html
http://docs.python.org/lib/ctypes-pointers.html
>From there on geting to this is farly straight forward:
from ctypes import *
from ctypes.wintypes import WORD
class SYSTEMTIME(Structure):
_fields_ = [
( 'wYear', WORD ),
( 'wMonth', WORD ),
( 'wDayOfWeek', WORD ),
( 'wDay', WORD ),
( 'wHour', WORD ),
( 'wMinute', WORD ),
( 'wSecond', WORD ),
( 'wMilliseconds', WORD ),
]
GetSystemTime = windll.kernel32.GetSystemTime
st = SYSTEMTIME()
GetSystemTime( pointer( st ) )
print st.wYear, st.wMonth, st.wDayOfWeek
A bit more digging into the docs will get to this:
prototype = WINFUNCTYPE( None, POINTER( SYSTEMTIME ) )
paramflags = (1, "lpSystemTime" ),
GetSystemTime = prototype(("GetSystemTime", windll.kernel32), paramflags )
st = SYSTEMTIME()
GetSystemTime( st )
print st.wYear, st.wMonth, st.wDayOfWeek
Which will give a much better error message if you try to
pass something other than a SYSTEMTIME, as well as wrapping
the argument in pointer for you.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
More information about the Python-list
mailing list