🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
12 messages
12 total messages Started by D Ray Sat, 17 Mar 2007 17:50
NetRemoteTOD to Get Server Time
#2256
Author: D Ray
Date: Sat, 17 Mar 2007 17:50
22 lines
1619 bytes
Dumb Question Alert - the following question may seem trivial to some, 
but I seem to be having a lot of trouble with it.

I've been using NetRemoteTOD to get server time but seem to have trouble 
getting it work right consistently with changes in DST and timezones, 
generally.

Is there some straightforward way of adjusting the results of 
NetRemoteTOD so that it always works --

a) Regardless of the time zone the server is in;
b) Regardless of the time zone the client is in;
c) Regardless of the DST status of both client and server; and
d) So that the client always ends up with the correct local time?

I think everything you need to do this is available either from the 
NetRemoteTOD call or from settings on the local machine, but I've just 
not been able to tie it all together.

Any help will be appreciated; TIA.

DR
Re: NetRemoteTOD to Get Server Time
#2257
Author: Bob Gonder
Date: Sat, 17 Mar 2007 20:21
11 lines
1250 bytes
D Ray wrote:

>Is there some straightforward way of adjusting the results of 
>NetRemoteTOD so that it always works --

Don't know if this _always_ works, but should be pretty close

NetRemoteTOD( URL, &tod )
UTC_hours = tod->tod_hours +( tod-> tod_timezone/60 )
GetTimeZoneInformation( &tzi );
Local Time = UTC_hours - ( tzi.Bias/60 )
Re: NetRemoteTOD to Get Server Time
#2270
Author: D Ray
Date: Mon, 19 Mar 2007 15:56
5 lines
1143 bytes
Bob

Thanks for your reply.

This gets close, but doesn't really deal with DST.
Re: NetRemoteTOD to Get Server Time
#2272
Author: Bob Gonder
Date: Mon, 19 Mar 2007 16:59
5 lines
1140 bytes
D Ray wrote:

>This gets close, but doesn't really deal with DST.

Which part doesn't?
Re: NetRemoteTOD to Get Server Time
#2276
Author: Dan
Date: Mon, 19 Mar 2007 19:25
16 lines
1587 bytes
Bob Gonder wrote:
> D Ray wrote:
> 
>> This gets close, but doesn't really deal with DST.
> 
> Which part doesn't?
> 
> 
I was wondering how to do this awhile back; didn't know such a function 
existed.  thanks..

Now the stupid question; how can I get it to work?  I made a simple VCL 
application with a button that should show me the time of day returned 
by NetReportTOD, and I get an error "Multiple declaration for 
NET_API_STATUS" when I include <lmremutl.h> but then an error that 
NetRemoteTOD doesn't exist if I don't.. what file should I be including?
Re: NetRemoteTOD to Get Server Time
#2279
Author: Bob Gonder
Date: Tue, 20 Mar 2007 03:02
16 lines
1814 bytes
Dan wrote:

>Now the stupid question; how can I get it to work?  I made a simple VCL 
>application with a button that should show me the time of day returned 
>by NetReportTOD, and I get an error "Multiple declaration for 
>NET_API_STATUS" when I include <lmremutl.h>

LMCONS.H defines that, and should have proper header guards to stop
multiple inclusions. (For example: RAS.H also includes it)

> but then an error that 
>NetRemoteTOD doesn't exist if I don't.. what file should I be including?

Which error would that be? I can think of 2 that sotta mean what you
said. Best guess without actual error message, is you didn't include
the netapi32.lib in your project.
Re: NetRemoteTOD to Get Server Time
#2282
Author: D Ray
Date: Tue, 20 Mar 2007 05:23
50 lines
2697 bytes
Not sure, but it looks like this works (still have some testing to do) 
-- RetVal is a struct containing the result of the call to NetRemoteTOD 
-- thanks for your replies...

DR
=====================================================================

         TIME_ZONE_INFORMATION tzi;
         DWORD TZStatus = GetTimeZoneInformation (&tzi);
         //
         //   figure out whether there is a DST bias or not
         //
         long DSTBias = 0;
         if (TZStatus == TIME_ZONE_ID_DAYLIGHT)
             DSTBias = tzi.DaylightBias;
         else
             DSTBias = 0L;

         //
         //   compute local hours
         //
         long LocalHours = RetVal.CurrentHour - (tzi.Bias/60) - 
(DSTBias/60);

         //
         //  if LocalHours is negative, we will have to add 23 to it -- 
and if we
         //      do that, we'll have to reduce the day by one.  But this 
is easier
         //      done after the date has been encoded as a TDateTime
         //
         bool DecrementDay = false;
         if (LocalHours < 0)
         {
             LocalHours += 23;
             DecrementDay = true;

         }

         //
         //   compute the combined regular time and DST bias
         //
         Bias = LocalHours - RetVal.CurrentHour;
         T = EncodeDateTime (RetVal.CurrentYear, RetVal.CurrentMonth, 
RetVal.CurrentDay,
                                       LocalHours, RetVal.CurrentMins,
                                       RetVal.CurrentSecs, 0);
         if (DecrementDay)
             T = IncDay (T, -1);
         return;
Re: NetRemoteTOD to Get Server Time
#2286
Author: Dan
Date: Tue, 20 Mar 2007 21:46
42 lines
2362 bytes
Simple Program:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include <lmremutl.H >
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
         : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   String URL = "\\djsrv6";
   TIME_OF_DAY_INFO TOD;


        NetRemoteTOD( URL, &TOD );
}
//---------------------------------------------------------------------------

complie as shown above, yields:
[C++ Error] lmremutl.H(61): E2238 Multiple declaration for 'NET_API_STATUS'
[C++ Error] lmremutl.H(55): E2344 Earlier declaration of 'NET_API_STATUS'
etc...

compiling with #include <lmcons.h> instead, or no #include yields the 
same errors:
[C++ Error] Unit1.cpp(23): E2451 Undefined symbol 'TIME_OF_DAY_INFO'
[C++ Error] Unit1.cpp(26): E2268 Call to undefined function 'NetRemoteTOD'
etc..

What am I doing wrong?
Re: NetRemoteTOD to Get Server Time
#2287
Author: Bob Gonder
Date: Wed, 21 Mar 2007 02:10
19 lines
2111 bytes
Dan wrote:

>complie as shown above, yields:
>[C++ Error] lmremutl.H(61): E2238 Multiple declaration for 'NET_API_STATUS'
>[C++ Error] lmremutl.H(55): E2344 Earlier declaration of 'NET_API_STATUS'

Those aren't declaration lines.
These are usage lines.
That means they weren't expected.
First thing to try when that happens is moving the header to where it
belongs. In this case, probably immediately after #pragma hdrdstop.
If not there, then before #include <vcl>
IMO all system headers belong before any application headers.

If that still doesn't work, check the header includes LMCONS.H
You didn't say what version you were using, but 5 and 2006 both have
slightly different line numbers from what you show.
If your version of lmremutil doesn't include lmcons, then include it
yourself
Re: NetRemoteTOD to Get Server Time
#2199
Author: Dan
Date: Wed, 21 Mar 2007 18:08
6 lines
1417 bytes
In this case, probably immediately after #pragma hdrdstop.
> If not there, then before #include <vcl>
> IMO all system headers belong before any application headers.

Interesting; I have never heard of that before.. But lo and behold it works.
Thanks.
Re: NetRemoteTOD to Get Server Time
#2200
Author: Alan Bellingham
Date: Wed, 21 Mar 2007 20:03
16 lines
1744 bytes
Bob Gonder <notbg@notmindspring.invalid> wrote:

>IMO all system headers belong before any application headers.

IMO all system headers required by such application headers should have
been included by the application headers.

So I tend to put any additional system headers *after* all application
headers, because that way, I find out where idempotency is failing
early.

Alan Bellingham
-- 
Team Thai Kingdom
<url:http://www.borland.com/newsgroups/> Borland newsgroup descriptions
<url:http://www.borland.com/newsgroups/netiquette.html>      netiquette
Re: NetRemoteTOD to Get Server Time
#2202
Author: Bob Gonder
Date: Thu, 22 Mar 2007 00:30
20 lines
2177 bytes
Alan Bellingham wrote:
>Bob Gonder  wrote:
>
>>IMO all system headers belong before any application headers.
>
>IMO all system headers required by such application headers should have
>been included by the application headers.

Yes, of course.. In a well-written, running program (or at least
compiling) that makes it nice, so you don't need to remember to
include x.h before y.h when all you want to use is y.

I probably mispoke, trying to convey a sense of urgency in the
placement of includes before "magic invocations" which seemed to make
the compiler skip a cog on that header.
By placing the lmremutil prior to other headers and pragmas, the
offending party doesn't get to mess with it (hopefully it will mess
with something else, and you can track it down). Perhaps even Unit1.h
was to blame. Moving it above the app headers eliminates most
suspects.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads