
Code:
'----------------------------------------------------------------------------------- Function InitThread(ByVal x As Long) As Long Local TdSt As String Local TmpSt As String Local Year As String Local Month As String Local Day As String Local Hour As String Local Minute As String Local Second As String Local s As String Local Y As Long Local Start As Long Local vbDate As Double '**DNJ** Local Delay As Double Local st As SYSTEMTIME '**DNJ** Local bc As SYSTEMTIME 'Buffer BEFORE CHANGE Local ac As SYSTEMTIME 'Compare to AFTER CHANGE Year = " Year" Month = " Month" Day = " Day" Hour = " Hour" Minute = " Minute" Second = " Second" s = "s" MousePtr 11 Menu Set State mMenu,%IDM_ACHECK,%MF_DISABLED Menu Set State pMenu,%IDM_ACHECK,%MF_DISABLED Control Set Text hDlg, %PCTIME,"" Control Set Text hDlg, %ATOMTIME,"" Control Set Text hDlg, %ID_NETDELAY,"" 'Call the AtomicTime in DLL here.... PCTime = GetPCTimeandDate(DateFormat,TimeFormat," ",tzinfo) If IsTrue SoundFlag Then Result = PlayWavFromResource(hInstance,WAVE + "2",WAV + "02") GetLocalTime bc 'BEFORE CHANGE MousePtr 11 UTCTime = CheckAtomicTime(nServer,Val(AtomPort),aTimeOut, Delay,st) MousePtr 0 If IsTrue SoundFlag Then Result = PlayWavFromResource(hInstance,WAVE + "3",WAV + "03") Statistics.AtomicChecked = Statistics.AtomicChecked + 1 Control Set Text hDlg, %ID_STATSTEXT2,Trim$(Str$(Statistics.AtomicChecked)) Control Set Text hDlg, %PCTIME,PCTime Control Set Text hDlg, %ATOMTIME,UTCTime Control Set Text hDlg, %ID_NETDELAY,Trim$(Str$(Delay)) + " ms" If IsTrue UseLog Then LogEvent "**** Check Atomic Clock ****" LogEvent "PC Time: " + PCTime LogEvent "Atomic Time: " + UTCTime LogEvent "Network Delay: " + Trim$(Str$(Delay)) + " ms" End If If SoundFlag = -999 Then SoundFlag = %TRUE 'Re-enable sound 'NIST TIME SERVER (Nuclear) '51468 99-10-17 05:12:27 15 0 0 888.6 UTC(NIST) * If Right$(UTCTime,2) = "* " Then ' Convert date and time to a SYSTEMTIME structure using a date VARIANT vbDate = StrToVbDate(Parse$(UTCTime, Any " ",2) + " " + Parse$(UTCTime, Any " ",3)) VariantTimeToSystemTime vbDate, st ElseIf Len(UTCTime) = 5 Then RFC868toSystemTime CvDwd(UTCTime), st 'ElseIf 'Internet Time Server '"Wed, 13 Oct 1999 15:07:52 -0700" ElseIf Len(UTCTime) < 2 Then Function = 0 Exit Function End If 'Verify we are running on Windows Server osinfo.dwOsVersionInfoSize = SizeOf(osinfo) GetVersionEx osinfo If osinfo.dwPlatformId = %VER_PLATFORM_WIN32_NT Then ' Verify We're running Windows NT, adjust the process' token so that we can Set the time If IsTrue SetTimePrivilege Then Result = SendMessage(%HWND_BROADCAST, %WM_TIMECHANGE, 0, 0) Result = SetSystemTime(st) ' Use this for troubleshooting format only ' Control Set Text hDlg, %PCTIME,FormatOutPut(1) 'After adjustment Else Control Set Text hDlg, %PCTIME,"Error setting time! " Control Set Text hDlg, %ATOMTIME,"Could not gain rights to change the time" Exit Function End If Else Result = SendMessage(%HWND_BROADCAST, %WM_TIMECHANGE, 0, 0) Result = SetSystemTime(st) End If 'Use this code to display the time difference: GetLocalTime ac ac.wyear = Abs(bc.wyear - ac.wyear) ac.wmonth = Abs(bc.wmonth - ac.wmonth) ac.wday = Abs(bc.wday - ac.wday) ac.wHour = Abs(bc.whour - ac.whour) ac.wMinute = Abs(bc.wMinute - ac.wminute) ac.wsecond = Abs(bc.wsecond - ac.wsecond) If ac.wyear <> 1 Then Year = Year + s If ac.wmonth <> 1 Then Month = Month + s If ac.wday <> 1 Then Day = Day + s If ac.wHour <> 1 Then Hour = Hour + s If ac.wMinute <> 1 Then Minute = Minute + s If ac.wsecond <> 1 Then Second = Second + s TdSt = Trim$(Str$(ac.wyear)) + Year + " " + Trim$(Str$(ac.wmonth)) + Month + " " + Trim$(Str$(ac.wday)) + Day + " " +_ Trim$(Str$(ac.whour)) + Hour + " " + Trim$(Str$(ac.wminute)) + Minute + " " + Trim$(Str$(ac.wsecond)) + Second + " " Control Set Text hDlg, %IDTIMEDIFF, TdSt Menu Set State mMenu,%IDM_ACHECK,%MF_ENABLED Menu Set State pMenu,%IDM_ACHECK,%MF_ENABLED 'Set Global Flag to False here g_lngInitThreadHandle = %FALSE End Function
------------------
Scott
mailto:[email protected][email protected]</A>
[This message has been edited by Scott Turchin (edited April 08, 2000).]
Leave a comment: