How to set Time (SOLVED)

How to set Time (SOLVED)

Postby frose » 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
Last edited by frose on Tue May 12, 2009 10:39 am, edited 1 time in total.
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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: How to set Time

Postby nageswaragunupudi » Mon May 11, 2009 1: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
User avatar
nageswaragunupudi
 
Posts: 10622
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to set Time

Postby frose » Mon May 11, 2009 2: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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: How to set Time

Postby Enrico Maria Giordano » Mon May 11, 2009 8:42 pm

Try this:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to set Time

Postby frose » Tue May 12, 2009 7:03 am

Enrico,
for some reason the class TReg32() doesn't work for me :-(

This code is ok:
Code: Select all  Expand view
#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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: How to set Time

Postby Enrico Maria Giordano » Tue May 12, 2009 8:40 am

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How to set Time

Postby frose » Tue May 12, 2009 8: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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: How to set Time (SOLVED)

Postby frose » 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
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 29 guests