Link to home
Start Free TrialLog in
Avatar of SADiver
SADiver

asked on

How to set the system date/time of the Pocket PC

Yeah I know it sounds like a lame question, but how do you do this?
The Now, Today and Time functions/properties are all readonly now.
Trying to set datestring throws exception:not supported
The only thing I could see with potential was the SetLocalTime API from the CorLib.DLL, but I am unable to get this working in VB.NET...
ASKER CERTIFIED SOLUTION
Avatar of iboutchkine
iboutchkine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SADiver
SADiver

ASKER

Hi iboutchkine,
I had to change the library to "CoreDLL.DLL" in your code, but thanks still !
I tried your suggestion, but got another exception:
e      {System.NotSupportedException}      System.Exception

I tried doing it with the SetLocalTime API as well with the same results
Avatar of SADiver

ASKER

OK...

Here is how I managed to get it to work:
I wrote a C# (unsafe) class in a SmartDeviceApplication classlibrary.
Here is the code for the library:

using System;
using System.Data;
using System.Runtime.InteropServices;

namespace SmartDeviceApplication2
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      public unsafe class cSetDateTime
      {
            public cSetDateTime()
            {
            }
            
            private struct SystemTime
            {
                  public UInt16 Year ;
                  public UInt16 Month ;
                  public UInt16 DayOfWeek ;
                  public UInt16 Day ;
                  public UInt16 Hour ;
                  public UInt16 Minute ;
                  public UInt16 Second ;
                  public UInt16 MilliSecond ;
            }

            [DllImport("coredll.dll")]
            private static extern Boolean SetLocalTime(SystemTime *lpSystemTime );

            public unsafe Boolean SetLocalDateTime(DateTime NewDateTime)
            {
                  try
                  {
                        SystemTime t;
                        t = new SystemTime();
                        t.Hour = (ushort)NewDateTime.Hour;
                        t.Minute = (ushort)NewDateTime.Minute;
                        t.Month = (ushort)NewDateTime.Month;
                        t.Day = (ushort)NewDateTime.Day;
                        t.Year = (ushort)NewDateTime.Year;
                        t.DayOfWeek = (ushort)NewDateTime.DayOfWeek;

                        SetLocalTime(&t);
                        return true;
                  }
                  catch
                  {
                        return false;
                  }
            }

      }
}


I then referenced the DLL that compiled from this in my VB.NET SmartDeviceApplication, and managed to get it to work that way...
For your effort, I believe you still earn the points iboutchkine, but could you maybe explain why it is "not supported" in VB.NET?

Avatar of Bob Learned
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: iboutchkine {http:#9139135}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer