Set system clock

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Set system clock

Peter Kenny-2
Hi all

I would like to ask for advice. I want to be able to set the system clock
programmatically (my computer clock seems to be erratic, but I can get a
reliable time from my modem). According to MSDN there is a function
GetSystemTime in kernel32.dll, which takes a SYSTEMTIME argument and returns
a Boolean for success/failure. This is not one of the functions exposed in
the KernelLibrary class, so I would like to add it. I have looked at the
other function wrappers in the class, and I can see the general pattern, but
I would like to be sure before I start messing around. I thought I could
generate the wrapper automatically using a tool like the Active-X Component
Wizard, but I cannot see how to do it. Could anyone please advise me?

Thanks in advance.

--
Best wishes

Peter Kenny


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Set system clock

Peter Kenny-2
"Peter Kenny" wrote...
> According to MSDN there is a function GetSystemTime in kernel32.dll, which
> takes a SYSTEMTIME argument and returns a Boolean for success/failure.

Sorry - I'm going dotty. The function I want is /SetSystemTime/


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Set system clock

Ian B-2
In reply to this post by Peter Kenny-2
Peter,

>    According to MSDN there is a function
>GetSystemTime in kernel32.dll, which takes a SYSTEMTIME argument and returns
>a Boolean for success/failure. This is not one of the functions exposed in
>the KernelLibrary class,

It _is_ present in a clean Dolphin 6 Pro image.  NB It needs a
parameter so you should be looking for #getSystemTime:

>  Could anyone please advise me?

All you need to do is add one method to KernelLibrary

setSystemTime: lpSystemTime
        <stdcall: void SetSystemTime SYSTEMTIME*>
        ^self invalidCall

You can then evaluate ...

st := SYSTEMTIME new.
KernelLibrary default getSystemTime: st.

to get the system time, wait a few seconds and then evaluate ...

KernelLibrary default setSystemTime: st.

and the system clock will revert to the previous value.  Obviously, if
you change st instVars then you can set the Date/Time to whatever you
want.


--
Ian

The From address is valid - for the moment


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Set system clock

Ian B-2
>setSystemTime: lpSystemTime
> <stdcall: void SetSystemTime SYSTEMTIME*>
> ^self invalidCall

or to be precise

setSystemTime: lpSystemTime
        <stdcall: bool SetSystemTime SYSTEMTIME*>
        ^self invalidCall
--
Ian

The From address is valid - for the moment


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Set system clock

Peter Kenny-2
"Ian B"  wrote...
>
>
> setSystemTime: lpSystemTime
> <stdcall: bool SetSystemTime SYSTEMTIME*>
> ^self invalidCall
> --

Ian

Many thanks. I just pasted this in, and of course it worked fine. It is
close to what I had thought of, but I had missed the need for the * on
SYSTEMTIME*, so I am glad I asked.

Peter


Loading...