Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Wednesday, November 16, 2005

managed C++ notes

public ref class MyClass
{
public:
    static System::Guid MyClassGuid = *(gcnew Guid ("B6806700-E2B1-4022-9D4B-B0205CB37935"));
};

convert time_t to tm via gmtime/localtime, then you can refer to the this page.
http://lists.gnu.org/archive/html/dotgnu-pnet-commits/2003-02/msg00221.html
using System;
using System.Runtime.InteropServices;

__module
{

        // Get the current system time in UTC.
        public static long __syscall_utc_time()
                        {
                                return DateTime.UtcNow.Ticks;
                        }

        // Get the current system time in local time.
        public static long __syscall_local_time()
                        {
                                return DateTime.Now.Ticks;
                        }

        // Unpack a tick value into a "struct tm" structure.
        public static void __syscall_unpack_time
                                (long ticks, IntPtr tm, bool is_local)
                        {
                                DateTime dt;
                                if(is_local)
                                {
                                        long tz = __syscall_utc_time() -
__syscall_local_time();
                                        dt = new DateTime(ticks + tz);
                                }
                                else
                                {
                                        dt = new DateTime(ticks);
                                }
                                Marshal.WriteInt32(tm, 0, dt.Second);
                                Marshal.WriteInt32(tm, 4, dt.Minute);
                                Marshal.WriteInt32(tm, 8, dt.Hour);
                                Marshal.WriteInt32(tm, 12, dt.Day);
                                Marshal.WriteInt32(tm, 16, dt.Month - 1);
                                Marshal.WriteInt32(tm, 20, dt.Year - 1900);
                                Marshal.WriteInt32(tm, 24, (int)(dt.DayOfWeek));
                                Marshal.WriteInt32(tm, 28, dt.DayOfYear);
                                Marshal.WriteInt32(tm, 32, 0);  /* TODO -
tm_isdst */
                        }

} // __module

0 Comments:

Post a Comment

<< Home