FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to set Time (SOLVED)
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
How to set Time (SOLVED)
Posted: Mon May 11, 2009 11:52 AM

Hi,

want to set the system time with SetTime( <nHour>, <nMinutes>, [<nSeconds>], [<nMillSecs>] ).
This function use Coordinated Universal Time (UTC), so I have to calculate the local time zone first.
But the function TimeZone() always return 0, though my machine is in GMT+1 with daylight saving on (UTC+2)!

Thanks in advance

Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to set Time
Posted: Mon May 11, 2009 01:31 PM

working for me
( we are +5.30, so i changed the rounding off ) subject to that it works well
function timezone is in random.prg

Regards



G. N. Rao.

Hyderabad, India
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: How to set Time
Posted: Mon May 11, 2009 02:47 PM

The function TimeZone() always return 0, though the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\Bias is 'ffffffc4'.

What can I do or test?

Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to set Time
Posted: Mon May 11, 2009 08:42 PM
Try this:

Code (fw): Select all Collapse
#define  HKEY_LOCAL_MACHINE  2147483650

function TimeZone() 

   local oReg, nRetVal 
   
   oReg = TReg32():New( HKEY_LOCAL_MACHINE,;
                         "SYSTEM\CurrentControlSet\Control\TimeZoneInformation", .f. ) 
   nRetVal = oReg:Get( "ActiveTimeBias", 0 ) 
   oReg:Close() 

   nRetVal = Round( nRetVal / 60, 0 ) * -1 
   
return nRetVal


EMG
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: How to set Time
Posted: Tue May 12, 2009 07:03 AM
Enrico,
for some reason the class TReg32() doesn't work for me :-)

This code is ok:
Code (fw): Select all Collapse
#define HKEY_LOCAL_MACHINE 2147483650
#define REG_SZ 0
#define REG_DWORD 4
#define KEY_ALL_ACCESS 983103

FUNCTION My_Get_Reg32( cKey, cSubkey, uVar)
   //
   // Get a key from the registry
   //
   LOCAL hKey := 0
   LOCAL nType
   LOCAL cData := SPACE( 256 )
   LOCAL nSize := LEN( cData )
   LOCAL nData
   //
   Default cKey    := "SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
    Default cSubkey := "ActiveTimeBias"
    Default uVar    := 0
   //
   IF Valtype( uVar ) == "N"
      nType := REG_DWORD
   ELSE
      nType := REG_SZ
   ENDIF
   
   REGOPENKEY( HKEY_LOCAL_MACHINE, cKey, 0, KEY_ALL_ACCESS, @hKey )

   REGQUERYVALUE( hKey, cSubkey, 0, @nType, @cData, @nSize)

   REGCLOSEKEY( hKey )
   
   IF Valtype( uVar ) == "N"
      nData := BIN2L( cData )
      cData := Str( nData )
   ENDIF
  
RETURN cData

DLL32 FUNCTION REGOPENKEY( hKey AS LONG, cSubKey AS LPSTR, nOptions AS DWORD, nSamDesired AS DWORD, @nHandle AS PTR ) AS LONG;
PASCAL FROM "RegOpenKeyExA" LIB "advapi32.dll"

DLL32 FUNCTION REGQUERYVALUE( hKey AS LONG, cDataName AS LPSTR, nReserved AS LONG, @nType AS PTR, @cData AS LPSTR, @nSize AS PTR ) AS LONG;
PASCAL FROM "RegQueryValueExA" LIB "advapi32.dll"

DLL32 FUNCTION REGCLOSEKEY( hKey AS LONG ) AS LONG;
PASCAL FROM "RegCloseKey" LIB "advapi32.dll"

It returns -120 ( GMT + 1 hour + daylight saving = 2 hours)!

Thanks to you and Rao
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to set Time
Posted: Tue May 12, 2009 08:40 AM

That's correct. Try my TimeZone() modification and you'll get 2.

EMG

Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: How to set Time
Posted: Tue May 12, 2009 08:59 AM

So now we comes closer to the prob: As reported above, the function My_Get_Reg32( cKey, cSubkey, uVar) works well, when calling separately. Also the function TimeZone() returns the right value 2.

But when I compile it in my main app the function My_Get_Reg32() returns 538976288 and TimeZone() 0!

There might be a names or version conflict in some dlls or libs?

Perhaps it's a similar prob as decribed by James Bott here viewtopic.php?f=3&t=13879, but renaming the DLL32 functions doesn't change anything :(

Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: How to set Time (SOLVED)
Posted: Tue May 12, 2009 10:44 AM

Solved :D

The reason was the file DLLCALL.C, which comes with PageScript!

I don't need it anymore, using FWH now :wink:

Enrico and Rao, thanks for your assistance.

Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86

Continue the discussion