Page 1 of 1

How to set Time (SOLVED)

PostPosted: Mon May 11, 2009 11:52 am
by frose
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

Re: How to set Time

PostPosted: Mon May 11, 2009 1:31 pm
by nageswaragunupudi
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

Re: How to set Time

PostPosted: Mon May 11, 2009 2:47 pm
by frose
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?

Re: How to set Time

PostPosted: Mon May 11, 2009 8:42 pm
by Enrico Maria Giordano
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

Re: How to set Time

PostPosted: Tue May 12, 2009 7:03 am
by frose
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

Re: How to set Time

PostPosted: Tue May 12, 2009 8:40 am
by Enrico Maria Giordano
That's correct. Try my TimeZone() modification and you'll get 2.

EMG

Re: How to set Time

PostPosted: Tue May 12, 2009 8:59 am
by frose
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 :(

Re: How to set Time (SOLVED)

PostPosted: Tue May 12, 2009 10:44 am
by frose
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.