SYSTEMTIME structure with some useful methods
示例#1
0
        static void Main(string[] args)
        {
            TIME_ZONE_INFORMATION tz = new TIME_ZONE_INFORMATION();
            GetTimeZoneInformation(ref tz);

            string s = args[0];
            System.Globalization.DateTimeFormatInfo dtfi =
                new System.Globalization.DateTimeFormatInfo();
            dtfi.FullDateTimePattern = "dd/MM/yyyy HH:mm:ss zz";
            dtfi.DateSeparator = "/";
            dtfi.TimeSeparator = ":";
            DateTime dt =
                DateTime.Parse(s, dtfi);

            
            SYSTEMTIME time = new SYSTEMTIME(dt);
            //time.wDay = (ushort)dt.Day;
            //time.wHour = (ushort)dt.Hour;
            //time.wDayOfWeek = (ushort)dt.DayOfWeek;
            //time.wMilliseconds = (ushort)dt.Millisecond;
            //time.wMinute = (ushort)dt.Minute;
            //time.wMonth = (ushort)dt.Month;
            //time.wSecond = (ushort)dt.Second;
            //time.wYear = (ushort)dt.Year;

            SetSystemTime(ref time);
        }
示例#2
0
        private static void Main(string[] args)
        {
            if (args.Length == 5)
            {
                var time = new SYSTEMTIME
                               {
                                   wDay = ushort.Parse(args[0]),
                                   wMonth = ushort.Parse(args[1]),
                                   wYear = ushort.Parse(args[2]),
                                   wHour = ushort.Parse(args[3]),
                                   wMinute = ushort.Parse(args[4])
                               };
                SetTime(time);
                return;
            }
            if (File.Exists("date.txt"))
            {

                var tr = new StreamReader("date.txt");
                string dateString = tr.ReadLine();
                if (dateString != null)
                {
                    dateString = dateString.Trim();
                    DateTime convertedDate = DateTime.Parse(dateString);
                    SetTime(convertedDate);
                }
            }
            else
            {
                SetTime(1, 1, 2012, 12, 00);
            }
        }
示例#3
0
文件: Program.cs 项目: ohel/setclock
        static void Main(string[] args)
        {
            if (args.Length == 0 || (new string[] { "help", "--help", "/?" }).Contains(args[0]))
            {
                System.Console.WriteLine("Give as the only parameter the time difference in hours. For example \"SetClock.exe -2\" moves the clock two hours backwards.");
                return;
            }

            double delta = 0;
            try
            {
                delta = Convert.ToDouble(args[0]);
            }
            catch
            {
                System.Console.WriteLine("Error converting input parameter to time difference.");
                return;
            }

            var newDateTime = DateTime.Now.ToUniversalTime().AddHours(delta);
            var newSystemTime = new SYSTEMTIME();
            newSystemTime.wYear = Convert.ToInt16(newDateTime.Year);
            newSystemTime.wMonth = Convert.ToInt16(newDateTime.Month);
            newSystemTime.wDay = Convert.ToInt16(newDateTime.Day);
            newSystemTime.wDayOfWeek = Convert.ToInt16(newDateTime.DayOfWeek);
            newSystemTime.wHour = Convert.ToInt16(newDateTime.Hour);
            newSystemTime.wMinute = Convert.ToInt16(newDateTime.Minute);
            newSystemTime.wSecond = Convert.ToInt16(newDateTime.Second);
            newSystemTime.wMilliseconds = Convert.ToInt16(newDateTime.Millisecond);

            SetSystemTime(ref newSystemTime);
        }
 private void GetTime()
 {
     SYSTEMTIME stime = new SYSTEMTIME();
     GetSystemTime(out stime);
     //labTime.Text = "Current Time:" + stime.wYear.ToString() + "/" + stime.wMonth.ToString() + "/" + stime.wDay.ToString() + "  " + stime.wHour.ToString() +":"+ stime.wMinute.ToString() +":"+ stime.wSecond.ToString();
     //lblError.Text = DateTime.Now.ToString("yyyyMMdd");
 }
示例#5
0
 private void ChangeDateDown(int numDays)
 {
     DateTime t = DateTime.Now.AddDays(-1);
     DateTime h = DateTime.Now.AddHours(0);
     SYSTEMTIME st = new SYSTEMTIME();
     st.FromDateTime(t);
     SetSystemTime(ref st);
 }
示例#6
0
 public REGISTRY_TIME_ZONE_INFORMATION(TIME_ZONE_INFORMATION tzi)
 {
     Bias = tzi.Bias;
     StandardDate = tzi.StandardDate;
     StandardBias = tzi.StandardBias;
     DaylightDate = tzi.DaylightDate;
     DaylightBias = tzi.DaylightBias;
 }
示例#7
0
 public static void SetTime(SYSTEMTIME time)
 {
     if (!SetLocalTime(ref time))
     {
         // The native function call failed, so throw an exception
         throw new Win32Exception(Marshal.GetLastWin32Error());
     }
 }
示例#8
0
 public static void SetTime(ushort day, ushort month, ushort year, ushort hour, ushort minute)
 {
     var time = new SYSTEMTIME {wDay = day, wMonth = month, wYear = year, wHour = hour, wMinute = minute};
     if (!SetLocalTime(ref time))
     {
         // The native function call failed, so throw an exception
         throw new Win32Exception(Marshal.GetLastWin32Error());
     }
 }
示例#9
0
        /// <summary>
        /// Gets current system time.
        /// </summary>
        /// <returns></returns>
        public static DateTime GetTime()
        {
            // Call the native GetSystemTime method
            // with the defined structure.
            SYSTEMTIME stime = new SYSTEMTIME();
            GetSystemTime(ref stime);

            var utc = new DateTime(stime.wYear, stime.wMonth, stime.wDay, stime.wHour, stime.wMinute, stime.wSecond, stime.wMilliseconds, DateTimeKind.Utc);
            return utc.ToLocalTime();
        }
示例#10
0
        // SYSTEMTIME�\����
        //
        // ABSTRACT	: DateTime�R���g���[���Ƀ��b�Z�[�W�𑗂�
        //
        public static System.IntPtr SetSystemTime(
			int				pid			, // �^�[�Q�b�g�̃v���Z�XID
			System.IntPtr	hDateTime	, // DATETIME�R���g���[���n���h��
			SYSTEMTIME		sysTime		)
        {
            System.IntPtr	hAccess;
            System.IntPtr	mem;
            System.IntPtr	result;
            GCHandle		gctemp;
            int				n;

            hAccess = InterProcess.OpenProcess(
                InterProcess.PROCESS_VM_OPERATION	|
                InterProcess.PROCESS_VM_READ		|
                InterProcess.PROCESS_VM_WRITE		,
                0									,
                pid									);

            mem = InterProcess.VirtualAllocEx(
                hAccess						,
                (System.IntPtr)0			,
                4096						,
                InterProcess.MEM_COMMIT		|
                InterProcess.MEM_RESERVE	,
                InterProcess.PAGE_READWRITE	);

            // �\���̂𑊎�v���Z�X�ɏ�������

            gctemp = GCHandle.Alloc( sysTime, GCHandleType.Pinned );

            System.IntPtr a = gctemp.AddrOfPinnedObject();

            InterProcess.WriteProcessMemory(
                hAccess					,
                mem						,
                a						,
                Marshal.SizeOf( sysTime ),
                out n					);

            result = Window.SendMessage(
                hDateTime			,
                DTM_SETSYSTEMTIME	,
                System.IntPtr.Zero	,		// GDT_VALID
                mem					);

            gctemp.Free();

            InterProcess.VirtualFreeEx( hAccess, mem, 4096, InterProcess.MEM_RELEASE );

            return result;
        }
示例#11
0
        public static void SetLocalTime(DateTime time)
        {
            var newTime = new SYSTEMTIME
            {
                wYear = (ushort)time.Year,
                wMonth = (ushort)time.Month,
                wDay = (ushort)time.Day,
                wHour = (ushort)time.Hour,
                wMinute = (ushort)time.Minute,
                wSecond = (ushort)time.Second,
                wMilliseconds = (ushort)time.Millisecond
            };

            SetLocalTime(ref newTime);
        }
示例#12
0
 /// <summary>
 /// Sets current system time.
 /// </summary>
 /// <param name="dateTime">Time to set as current system time.</param>
 public static void SetTime(DateTime dateTime)
 {
     dateTime = dateTime.ToUniversalTime();
     SYSTEMTIME stime = new SYSTEMTIME()
     {
         wYear = (ushort)dateTime.Year,
         wMonth = (ushort)dateTime.Month,
         wDay = (ushort)dateTime.Day,
         wHour = (ushort)dateTime.Hour,
         wMinute = (ushort)dateTime.Minute,
         wSecond = (ushort)dateTime.Second,
         wMilliseconds = (ushort)dateTime.Millisecond
     };
     SetSystemTime(ref stime);
 }
示例#13
0
        static void Main(string[] args)
        {
           
            string s = args[0];
            System.Globalization.DateTimeFormatInfo dtfi =
                new System.Globalization.DateTimeFormatInfo();
            dtfi.FullDateTimePattern = "dd/MM/yyyy HH:mm:ss";
            dtfi.ShortDatePattern = "dd/MM/yyyy";
            dtfi.ShortTimePattern = "HH:mm:ss";
            dtfi.DateSeparator = "/";
            dtfi.TimeSeparator = ":";
            

            string s1 = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss",dtfi);
            string s2 = s.Remove(s.Length - 4,4);
            string s3 = s.Substring(s.Length - 4, 4);

            DateTime dt =
                DateTime.Parse(s2, dtfi);


            SYSTEMTIME time = new SYSTEMTIME(dt);
            //time.wDay = (ushort)dt.Day;
            //time.wHour = (ushort)dt.Hour;
            //time.wDayOfWeek = (ushort)dt.DayOfWeek;
            //time.wMilliseconds = (ushort)dt.Millisecond;
            //time.wMinute = (ushort)dt.Minute;
            //time.wMonth = (ushort)dt.Month;
            //time.wSecond = (ushort)dt.Second;
            //time.wYear = (ushort)dt.Year;

            SetLocalTime(ref time);

            TIME_ZONE_INFORMATION tzI = new TIME_ZONE_INFORMATION();
            GetTimeZoneInformation(ref tzI);
            tzI.Bias = int.Parse(s3)*60;
            tzI.StandardBias = 0;
            //tzI.DaylightBias = 0;
            //tzI.StandardName = "Moscow";
            //tzI.DaylightName = "Moscow";
            //tzI.DaylightDate = time;
            //tzI.StandardDate = time;


            SetTimeZoneInformation(ref tzI);
            
            Microsoft.Win32.Registry.LocalMachine.Flush();
        }
示例#14
0
 public static void SetTime(DateTime timed)
 {
     var time = new SYSTEMTIME
                    {
                        wDay = (ushort) timed.Day,
                        wMonth = (ushort) timed.Month,
                        wYear = (ushort) timed.Year,
                        wHour = (ushort) timed.Hour,
                        wMinute = (ushort) timed.Minute
                    };
     if (!SetLocalTime(ref time))
     {
         // The native function call failed, so throw an exception
         throw new Win32Exception(Marshal.GetLastWin32Error());
     }
 }
示例#15
0
	///<summary>Set the windows system time.</summary>
	public static void SetTime(DateTime newTime) {
		// Call the native SetLocalTime method 
		// with the defined structure.
		SYSTEMTIME systime=new SYSTEMTIME();
		systime.wYear=(ushort)newTime.Year;
		systime.wMonth=(ushort)newTime.Month;
		systime.wDayOfWeek=(ushort)newTime.DayOfWeek;
		systime.wDay=(ushort)newTime.Day;
		systime.wHour=(ushort)newTime.Hour;
		systime.wMinute=(ushort)newTime.Minute;
		systime.wSecond=(ushort)newTime.Second;
		systime.wMilliseconds=(ushort)newTime.Millisecond;
		SetLocalTime(ref systime);
		string messageText="System date and time set to:  "+newTime.ToString("MM/dd/yyyy hh:mm:ss.fff tt")+".";
		EventLog.WriteEntry("OpenDental",messageText,EventLogEntryType.Information);
	}
示例#16
0
	public DigitalClockDisplay(bool is24Hour, bool suppressExtra)
	{
        f24Hour = is24Hour;
		fSuppress = suppressExtra;
		fSegmentedNumber = new SegmentedNumber();

        ptColon = new Point[2][];
        ptColon[0] = new Point[] { new Point(2, 21), new Point(6, 17), new Point(10, 21), new Point(6, 25) };
        ptColon[1] = new Point[] { new Point(2, 51), new Point(6, 47), new Point(10, 51), new Point(6, 55) };

        fcolonPolies = new PolygonG[2];
        fcolonPolies[0] = new PolygonG(ptColon[0]);
        fcolonPolies[1] = new PolygonG(ptColon[1]);

        fLastTime = new SYSTEMTIME();
        fThisTime = new SYSTEMTIME();
    }
        public BLUETOOTH_DEVICE_INFO(long address)
        {
            dwSize = 560;
            this.Address = address;
            ulClassofDevice = 0;
            fConnected = false;
            fRemembered = false;
            fAuthenticated = false;
#if WinXP
            stLastSeen = new SYSTEMTIME();
            stLastUsed = new SYSTEMTIME();

            // The size is much smaller on CE (no times and string not inline) it
            // appears to ignore the bad dwSize value.  So don't check this on CF.
            System.Diagnostics.Debug.Assert(Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_INFO)) == dwSize, "BLUETOOTH_DEVICE_INFO SizeOf == dwSize");
#endif
            szName = "";
        }
示例#18
0
        int IVsSolutionEventsProjectUpgrade.OnAfterUpgradeProject(IVsHierarchy pHierarchy, uint fUpgradeFlag, string bstrCopyLocation, SYSTEMTIME stUpgradeTime, IVsUpgradeLogger pLogger)
        {
            Debug.Assert(pHierarchy != null);

            Project upgradedProject = VsUtility.GetProjectFromHierarchy(pHierarchy);

            if (upgradedProject != null)
            {
                IList<IPackage> packagesToBeReinstalled = ProjectRetargetingUtility.GetPackagesToBeReinstalled(upgradedProject);

                if (!packagesToBeReinstalled.IsEmpty())
                {
                    pLogger.LogMessage((int)__VSUL_ERRORLEVEL.VSUL_ERROR, upgradedProject.Name, upgradedProject.Name,
                        String.Format(CultureInfo.CurrentCulture, Resources.ProjectUpgradeAndRetargetErrorMessage, String.Join(", ", packagesToBeReinstalled.Select(p => p.Id))));
                }
            }
            return VSConstants.S_OK;
        }
示例#19
0
 public static void SetTime(DateTime dt)
 {
     // Call the native GetSystemTime method
     // with the defined structure.
     SYSTEMTIME systime = new SYSTEMTIME();
     //GetSystemTime(ref systime);
     systime.wDay = (ushort)dt.Day;
     systime.wMonth = (ushort)dt.Month;
     systime.wYear = (ushort)dt.Year;
     systime.wHour = (ushort)dt.Hour;
     systime.wMinute = (ushort)dt.Minute;
     systime.wSecond = (ushort)dt.Second;
     // Set the system clock ahead one hour.
     //systime.wHour = (ushort)(systime.wHour + 1 % 24);
     SetSystemTime(ref systime);
     System.Diagnostics.Debug.WriteLine(string.Format("New time: " + systime.wHour.ToString() + ":"
         + systime.wMinute.ToString()+"\r\n"));
 }
示例#20
0
 public unsafe TIME_ZONE_INFORMATION(TIME_DYNAMIC_ZONE_INFORMATION dtzi)
 {
     Bias = dtzi.Bias;
     fixed (char* standard = StandardName)
     {
         for (int i = 0; i < 32; ++i)
         {
             standard[i] = dtzi.StandardName[i];
         }
     }
     fixed (char* daylight = DaylightName)
     {
         for (int i = 0; i < 32; ++i)
         {
             daylight[i] = dtzi.DaylightName[i];
         }
     }
     StandardDate = dtzi.StandardDate;
     StandardBias = dtzi.StandardBias;
     DaylightDate = dtzi.DaylightDate;
     DaylightBias = dtzi.DaylightBias;
 }
示例#21
0
 public static DateTime GetTime()
 {
     // Call the native GetSystemTime method
     // with the defined structure.
     SYSTEMTIME stime = new SYSTEMTIME();
     GetSystemTime(ref stime);
     
     // Show the current time.           
     string strDateTime=(
         stime.wDay.ToString() + "." + stime.wMonth.ToString() + "." + stime.wYear.ToString() + " "+
         stime.wHour.ToString() + ":"+ stime.wMinute.ToString()+":"+stime.wSecond.ToString() 
         );
     DateTime dt;
     try
     {
         dt = DateTime.Parse(strDateTime);
     }
     catch (SystemException sx)
     {
         System.Diagnostics.Debug.WriteLine("Exception in GetTime(): " + sx.Message + "\r\n");
         dt=DateTime.Now;
     }
     return dt;
 }
示例#22
0
 /// <summary>
 /// 静态方法。转换为System.DateTime类型。
 /// </summary>
 /// <param name="time">SYSTEMTIME类型的时间。</param>
 /// <returns></returns>
 public static DateTime ToDateTime(SYSTEMTIME time)
 {
     return(time.ToDateTime());
 }
示例#23
0
 static extern bool SystemTimeToFileTime(ref SYSTEMTIME lpSystemTime, ref FILETIME lpFileTime);
示例#24
0
 private static extern bool SystemTimeToFileTime([In] ref SYSTEMTIME lpSystemTime,
                                                 out System.Runtime.InteropServices.ComTypes.FILETIME lpFileTime);
示例#25
0
 public static extern long FileTimeToSystemTime(ref FILETIME FileTime, ref SYSTEMTIME SystemTime);
示例#26
0
 private extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);
示例#27
0
 public void SessionUpdated(Object session, SYSTEMTIME sysTime, Boolean toKillProcesses)
 {
     SystemTime.SetSystemTime(ref sysTime);
     ESessionUpdated(session, toKillProcesses);
 }
        /// <summary>クライアント生成 - Writeスレッド関数</summary>
        private void WriteSharedMemory()
        {
            // 共有メモリ(サーバ)
            SharedMemory sm = null;

            // スレッドID
            int managedThreadId = Thread.CurrentThread.ManagedThreadId;

            try
            {
                // 共有メモリを生成(256バイト)
                sm = new SharedMemory("my-sm", 256, "my-mtx");

                // マップ
                sm.Map(0, 0);
                // ロック
                sm.Lock();

                // システム時間、ローカル時間の「Manage SYSTEMTIME構造体」
                SYSTEMTIME[] csts = new SYSTEMTIME[2];

                // システム時間
                CmnWin32.GetSystemTime(out csts[0]);
                string systemTime =
                    string.Format("{0:0000}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}.{6:000}",
                                  csts[0].Year, csts[0].Month, csts[0].Day,
                                  csts[0].Hour, csts[0].Minute, csts[0].Second, csts[0].Milliseconds);

                // ローカル時間
                CmnWin32.GetLocalTime(out csts[1]);
                string localTime =
                    string.Format("{0:0000}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}.{6:000}",
                                  csts[1].Year, csts[1].Month, csts[1].Day,
                                  csts[1].Hour, csts[1].Minute, csts[1].Second, csts[1].Milliseconds);

                // 共有メモリを初期化
                sm.SetMemory(CmnClass.InitBuff(256), 256);

                // マーシャリング(「Unmanage SYSTEMTIME構造体」のバイト表現を取得)

                //// (1)
                //SYSTEMTIME cst = new SYSTEMTIME();
                //int sizeCst = Marshal.SizeOf(cst);
                //byte[] cstBytes = new byte[sizeCst];
                //byte[] cstsBytes = new byte[sizeCst * 2];

                //Array.Copy(CustomMarshaler.StructureToBytes(csts[0]), 0, cstsBytes, 0, sizeCst);
                //Array.Copy(CustomMarshaler.StructureToBytes(csts[1]), 0, cstsBytes, sizeCst * 1, sizeCst);

                // (2)
                byte[] cstsBytes = CustomMarshaler.StructuresToBytes(new object[] { csts[0], csts[1] }, 2);

                // 共有メモリへ書き込む。
                sm.SetMemory(cstsBytes, cstsBytes.Length);

                // 送信メッセージを表示
                this.SetResult_Client(
                    string.Format("({0})送信:{1}", managedThreadId,
                                  "\r\nsystemTime:" + systemTime + "\r\nlocalTime:" + localTime));
            }
            catch (Exception ex)
            {
                // エラーを表示
                this.SetResult_Client(
                    string.Format("({0})エラー:{1}", managedThreadId, ex.ToString()));
            }
            finally
            {
                if (sm != null)
                {
                    // 共有メモリをクローズ
                    // アンロック&マネージ・アンマネージリソースの解放
                    sm.Close();// ←コメントアウトするとGC任せになるが、ミューテックスの解放が遅れる!
                }
            }
        }
示例#29
0
文件: synTime.cs 项目: Diullei/Storm
 static string GetCurrentYear()
 {
     SYSTEMTIME st = new SYSTEMTIME();
     GetSystemTime(ref st);
     return st.wYear.ToString();
 }
示例#30
0
 public static extern bool FileTimeToSystemTime([In] ref FILETIME lpFileTime,
                                                out SYSTEMTIME lpSystemTime);
        int IVsSolutionEventsProjectUpgrade.OnAfterUpgradeProject(IVsHierarchy pHierarchy, uint fUpgradeFlag, string bstrCopyLocation, SYSTEMTIME stUpgradeTime, IVsUpgradeLogger pLogger)
        {
            NuGetUIThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                Debug.Assert(pHierarchy != null);

                var upgradedProject      = VsHierarchyUtility.GetProjectFromHierarchy(pHierarchy);
                var upgradedNuGetProject = await EnvDTEProjectUtility.GetNuGetProjectAsync(upgradedProject, _solutionManager);

                if (ProjectRetargetingUtility.IsProjectRetargetable(upgradedNuGetProject))
                {
                    var packagesToBeReinstalled = await ProjectRetargetingUtility.GetPackagesToBeReinstalled(upgradedNuGetProject);

                    if (packagesToBeReinstalled.Any())
                    {
                        pLogger.LogMessage((int)__VSUL_ERRORLEVEL.VSUL_ERROR, upgradedProject.Name, upgradedProject.Name,
                                           string.Format(CultureInfo.CurrentCulture, Strings.ProjectUpgradeAndRetargetErrorMessage, string.Join(", ", packagesToBeReinstalled.Select(p => p.Id))));
                    }
                }
            });

            return(VSConstants.S_OK);
        }
示例#32
0
 private static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
示例#33
0
        void DecryptHelper4(byte[] data, int index, uint[] key_src)
        {
            uint[] buf = new uint[0x50];
            int    i;

            for (i = 0; i < 0x10; ++i)
            {
                buf[i] = BigEndian.ToUInt32(data, index + 40 + 4 * i);
            }
            for (; i < 0x50; ++i)
            {
                uint v = buf[i - 16];
                v     ^= buf[i - 14];
                v     ^= buf[i - 8];
                v     ^= buf[i - 3];
                buf[i] = Binary.RotL(v, 1);
            }
            uint[] key = new uint[10];
            Array.Copy(key_src, key, 5);
            uint k0 = key[0];
            uint k1 = key[1];
            uint k2 = key[2];
            uint k3 = key[3];
            uint k4 = key[4];

            for (int buf_idx = 0; buf_idx < 0x50; ++buf_idx)
            {
                uint f, c;
                if (buf_idx < 0x10)
                {
                    f = k1 ^ k2 ^ k3;
                    c = 0;
                }
                else if (buf_idx < 0x20)
                {
                    f = k1 & k2 | k3 & ~k1;
                    c = 0x5A827999;
                }
                else if (buf_idx < 0x30)
                {
                    f = k3 ^ (k1 | ~k2);
                    c = 0x6ED9EBA1;
                }
                else if (buf_idx < 0x40)
                {
                    f = k1 & k3 | k2 & ~k3;
                    c = 0x8F1BBCDC;
                }
                else
                {
                    f = k1 ^ (k2 | ~k3);
                    c = 0xA953FD4E;
                }
                uint new_k0 = buf[buf_idx] + k4 + f + c + Binary.RotL(k0, 5);
                uint new_k2 = Binary.RotR(k1, 2);
                k1 = k0;
                k4 = k3;
                k3 = k2;
                k2 = new_k2;
                k0 = new_k0;
            }
            key[0] += k0;
            key[1] += k1;
            key[2] += k2;
            key[3] += k3;
            key[4] += k4;
            var ft = new FILETIME {
                DateTimeLow  = key[1],
                DateTimeHigh = key[0] & 0x7FFFFFFF
            };
            var sys_time = new SYSTEMTIME(ft);

            key[5] = (uint)(sys_time.Year | sys_time.Month << 16);
            key[7] = (uint)(sys_time.Hour | sys_time.Minute << 16);
            key[8] = (uint)(sys_time.Second | sys_time.Milliseconds << 16);

            uint flags = LittleEndian.ToUInt32(data, index + 40) | 0x80000000;
            uint rgb   = buf[1] >> 8; // BigEndian.ToUInt32 (data, index+44) >> 8;

            if (0 == (flags & 0x78000000))
            {
                flags |= 0x98000000;
            }
            key[6] = RegionCrc32(m_scheme.Region, flags, rgb);
            key[9] = (uint)(((int)key[2] * (long)(int)key[3]) >> 8);
            if (m_scheme.Version >= 2390)
            {
                key[6] += key[9];
            }
            unsafe
            {
                fixed(byte *data_fixed = data)
                {
                    uint *encoded = (uint *)(data_fixed + index);

                    for (i = 0; i < 10; ++i)
                    {
                        encoded[i] ^= key[i];
                    }
                }
            }
        }
示例#34
0
 static extern void GetSystemTime(ref SYSTEMTIME lpSystemTime);
示例#35
0
 static extern int SetSystemTime(ref SYSTEMTIME lpSystemTime);
示例#36
0
 public static extern long SystemTimeToTzSpecificLocalTime(IntPtr lpTimeZoneInformation, ref SYSTEMTIME lpUniversalTime, out SYSTEMTIME lpLocalTime);
        /// <summary>サーバ起動 - pollingスレッド関数</summary>
        /// <remarks>unsafeキーワードが必要になる</remarks>
        private void PollingSharedMemory()
        {
            // 共有メモリ(サーバ)
            SharedMemory sm = null;

            // スレッドID
            int managedThreadId = Thread.CurrentThread.ManagedThreadId;

            try
            {
                // 共有メモリを生成
                sm = new SharedMemory("my-sm", 256, "my-mtx");

                // マップ
                sm.Map(0, 0);

                // Polling開始を表示
                this.SetResult_Svr(
                    string.Format("Polling開始! - ThreadId:{0}", managedThreadId));

                // Polling処理

                while (!End)
                {
                    // システム時間、ローカル時間の「Manage SYSTEMTIME構造体」
                    SYSTEMTIME cst = new SYSTEMTIME();

                    byte[] cstBytes  = new byte[Marshal.SizeOf(cst)];
                    byte[] cstsBytes = new byte[Marshal.SizeOf(cst) * 2];

                    // 共有メモリから「Unmanage SYSTEMTIME構造体」配列のバイト表現を読み込む。
                    sm.GetMemory(out cstsBytes, cstsBytes.Length);

                    // マーシャリング(「Unmanage SYSTEMTIME構造体」配列のバイト表現を「Manage SYSTEMTIME構造体」へ変換)

                    //// (1)
                    //object[] os = new object[2];

                    //Array.Copy(cstsBytes, 0, cstBytes, 0, Marshal.SizeOf(cst));
                    //os[0] = CustomMarshaler.BytesToStructure(cstBytes, typeof(SYSTEMTIME));

                    //Array.Copy(cstsBytes, Marshal.SizeOf(cst) * 1, cstBytes, 0, Marshal.SizeOf(cst));
                    //os[1] = CustomMarshaler.BytesToStructure(cstBytes, typeof(SYSTEMTIME));

                    // (2)
                    object[] os = CustomMarshaler.BytesToStructures(cstsBytes, typeof(SYSTEMTIME), 2);

                    SYSTEMTIME[] csts = new SYSTEMTIME[] { (SYSTEMTIME)os[0], (SYSTEMTIME)os[1] };

                    // システム時間
                    string systemTime =
                        string.Format("{0:0000}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}.{6:000}",
                                      csts[0].Year, csts[0].Month, csts[0].Day,
                                      csts[0].Hour, csts[0].Minute, csts[0].Second, csts[0].Milliseconds);

                    // ローカル時間
                    string localTime =
                        string.Format("{0:0000}/{1:00}/{2:00} {3:00}:{4:00}:{5:00}.{6:000}",
                                      csts[1].Year, csts[1].Month, csts[1].Day,
                                      csts[1].Hour, csts[1].Minute, csts[1].Second, csts[1].Milliseconds);

                    // 受信メッセージを表示
                    this.SetResult_Svr(
                        string.Format("({0})受信:{1}", managedThreadId,
                                      "\r\nsystemTime:" + systemTime + "\r\nlocalTime:" + localTime));

                    Thread.Sleep(1000); // Polling間隔
                }

                // Polling停止を表示
                this.SetResult_Svr(
                    string.Format("Polling停止! - ThreadId:{0}", managedThreadId));
            }
            catch (Exception ex)
            {
                // エラーを表示
                this.SetResult_Svr(
                    string.Format("({0})エラー:{1}", managedThreadId, ex.ToString()));
            }
            finally
            {
                if (sm != null)
                {
                    // 共有メモリをクローズ
                    // アンロック&マネージ・アンマネージリソースの解放
                    sm.Close();// ←コメントアウトするとGC任せになるが、ミューテックスの解放が遅れる!
                }
            }
        }
示例#38
0
 public static extern Boolean FileTimeToSystemTime(ref winapi.Components.FILETIME lpFileTime, 
     out SYSTEMTIME lpSystemTime);
示例#39
0
 private extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);
示例#40
0
        static DateTime getDateTime(SYSTEMTIME systemTime)
        {
            DateTime dt = new DateTime(systemTime.Year, systemTime.Month, systemTime.Day, systemTime.Hour, systemTime.Minute, systemTime.Second);

            return(dt);
        }
示例#41
0
 public static extern bool SetSystemTime(ref SYSTEMTIME st);
示例#42
0
 public void SetDateTime(SYSTEMTIME systemTime)
 {
     SetSystemTime(ref systemTime);
 }
示例#43
0
 public static extern long SystemTimeToTzSpecificLocalTime(IntPtr lpTimeZoneInformation, ref SYSTEMTIME lpUniversalTime, out SYSTEMTIME lpLocalTime);
示例#44
0
 private static extern bool FileTimeToSystemTime
     (ref System.Runtime.InteropServices.ComTypes.FILETIME FileTime, ref SYSTEMTIME SystemTime);
示例#45
0
 public static extern bool GetSystemTime(out SYSTEMTIME systemTime);
示例#46
0
 public static extern bool SetLocalTime(ref SYSTEMTIME st);
示例#47
0
internal static extern bool SetLocalTime(ref SYSTEMTIME lpSystemTime);
示例#48
0
        static SYSTEMTIME getSystemTime(DateTime dt)
        {
            SYSTEMTIME st = new SYSTEMTIME(dt);

            return(st);
        }
示例#49
0
 public static extern int DLL_AddCountDown(ref RECT rect, int transparent, string fontname, int fontsize, int fontcolor, int format, ref SYSTEMTIME endtime, int fontstyle);
示例#50
0
文件: IEHistory.cs 项目: wpmyj/csharp
 private static extern int FileTimeToSystemTime(ref FILETIME lpFileTime, ref SYSTEMTIME lpSystemTime);
示例#51
0
文件: synTime.cs 项目: Diullei/Storm
 public static void SetNewSysTime(DateTime dateTime)
 {
     SYSTEMTIME st = new SYSTEMTIME(dateTime);
     Console.WriteLine("Time has been set: " + dateTime.ToLocalTime());
     SetSystemTime(ref st);
 }
示例#52
0
 public int AddCountDown(ref RECT rect, int transparent, string fontname, int fontsize, int fontcolor, eCountType format, ref SYSTEMTIME endtime, int fontstyle)
 {
     return(DLL_AddCountDown(ref rect, transparent, fontname, fontsize, fontcolor, (int)format, ref endtime, fontstyle));
 }
示例#53
0
文件: synTime.cs 项目: Diullei/Storm
 static extern void GetSystemTime(ref SYSTEMTIME lpSystemTime);
示例#54
0
 public static extern void DLL_GetLocalTime(ref SYSTEMTIME lpSystemTime);
示例#55
0
 public static extern long FileTimeToSystemTime(ref FILETIME FileTime, ref SYSTEMTIME SystemTime);
示例#56
0
 /// <summary>
 /// 获取当前系统时间
 /// </summary>
 /// <param name="lpSystemTime">系统时间变量</param>
 /// <returns></returns>
 public void GetLocalTime(ref SYSTEMTIME lpSystemTime)
 {
     DLL_GetLocalTime(ref lpSystemTime);
 }
示例#57
0
public static extern bool SetSystemTime(ref SYSTEMTIME st);
示例#58
0
 private static extern bool SetSystemTime(ref SYSTEMTIME st);
示例#59
0
//Then call the method with an instance of your struct like this:


      void  SetSysDateTime(int year,int month,int day,int hour,int min,int sec)
       {
           SYSTEMTIME st = new SYSTEMTIME();
        
           st.wYear = (short)year; // must be short
           st.wMonth = (short)month;
           st.wDay = (short)day;
           st.wHour =(short)hour;
           st.wMinute = (short)min;
           st.wSecond = (short)sec;

           SetLocalTime(ref st); 
       }
 private static extern bool SetLocalTime(ref SYSTEMTIME time);