Set WinCE 5.0 Time via CF?

T

Tomppa

Does anyone have an example of setting the system time or syncing to a time
service via .net code?

Thanks

CE 5.0 CF 2.0
 
J

jn1974

It's not possible directly, but with a P/Invoke

Put these inside the class:

[StructLayoutAttribute(LayoutKind.Sequential)]
private struct SYSTEMTIME
{
public short year;
public short month;
public short dayOfWeek;
public short day;
public short hour;
public short minute;
public short second;
public short milliseconds;
}

[DllImport("coredll.dll")]
static extern bool SetLocalTime(ref SYSTEMTIME time);

And the code would be:

DateTime Now = DateTime.Now;
SYSTEMTIME SystemNow;

SystemNow.year = (short)Now.Year;
SystemNow.month = (short)Now.Month;
SystemNow.dayOfWeek = (short)Now.DayOfWeek;
SystemNow.day = (short)Now.Day;
SystemNow.hour = (short)Now.Hour;
SystemNow.minute = (short)Now.Minute;
SystemNow.second = (short)Now.Second;
SystemNow.milliseconds = (short)Now.Millisecond;

SetLocalTime(ref SystemNow);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top