Page 1 of 2

C-function in FWH

Posted: Fri Apr 08, 2016 11:48 am
by Marc Vanzegbroeck
Hi,

In a SQL-database is a field with time and date, and I want to read it in FWH.
You can read it in C with the FromFileTime() function.
Can I convert it to FWH?

This is an example in C that convert the value.

Code: Select all

#include "stdafx.h"
using namespace System;
using namespace System::Globalization;

int _tmain(int argc, _TCHAR* argv[])
{
               System::DateTime fEventTime = System::DateTime::FromFileTime( 131032008000002432 );
               Console::Write("Date & Time = {0:MM/dd/yyyy hh:mm:ss tt}\n",fEventTime );
               getchar();
               return 0;
}
 

Re: C-function in FWH

Posted: Fri Apr 08, 2016 2:37 pm
by Antonio Linares
Marc,

Do you mean that you want to execute that C++ code from Harbour ?

Do you want to retrieve the date and time of a file ?

Can't you use a SQL query to retrieve those values from that field ?

Not sure what you mean

Re: C-function in FWH

Posted: Fri Apr 08, 2016 4:25 pm
by Marc Vanzegbroeck
Antonio,

Now if I show that field in the SQL-table, I see the value '131032008000002432'
I want to convert thqt value to a readable time/date format.
The C-function FromFileTime() should do that.

Re: C-function in FWH

Posted: Fri Apr 08, 2016 4:33 pm
by Antonio Linares
Marc,

What C compiler are you using ?

We may try it using a C++ file

Re: C-function in FWH

Posted: Fri Apr 08, 2016 4:43 pm
by Marc Vanzegbroeck
Antonio,

I use BCC as compiler.
A programmer that use that database,gave me that function after I asked him how I can convert it.
He also gave me an VB example

Code: Select all

Dim arHSCTIME As Long
Dim cstZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time")
Dim dtArchiveDate As DateTime
arHSCTIME = 131032008000002432
dtArchiveDate = DateTime.FromFileTime(arHSCTIME)
MsgBox(dtArchiveDate)
 
Then he gave me also that C++ example, after I told him that my program is compiled with a C-compiler....

Re: C-function in FWH

Posted: Fri Apr 08, 2016 5:02 pm
by Antonio Linares
Marc,

We need Mr. Rao's advise

surely he knows the best way to solve this without having to use C++

Re: C-function in FWH

Posted: Sat Apr 09, 2016 9:16 am
by Marc Vanzegbroeck
Antonio,

Is it not possible to use that function with

Code: Select all

#pragma BEGINDUMP
like you do with onther C-functions?

Re: C-function in FWH

Posted: Sat Apr 09, 2016 9:33 am
by Antonio Linares
Marc,

As such code uses C++ we need to create a .cpp file or use VSC2015 as we use C++ mode with it

Using Borland we can not use C++ code in #pragma BEGINDUMP ... ENDDUMP as we compile in C mode

Re: C-function in FWH

Posted: Sat Apr 09, 2016 11:50 am
by byte-one
Using Borland we can not use C++ code in #pragma BEGINDUMP ... ENDDUMP as we compile in C mode
Antonio, i only tested with FWH64 and Borland and #pragma BEGINDUMP ... ENDDUMP. It is functioning when i make with Harbour a file with extension "CPP". I have a PRG similar as your gdiplus.cpp and use #pragma BEGINDUMP ... ENDDUMP. Compiling without errors and warnings! The compiler switches automatically to C++-mode if extension is "CPP".
In 32bit we have to use compiler-switch -P

Re: C-function in FWH

Posted: Sat Apr 09, 2016 11:57 am
by nageswaragunupudi
We need to use BEGINDUMP and ENDDUMP only in PRG files.

When we compile *.cpp any compiler automatically switches to c++ mode and there is no point using BEGINDUP,ENDDUMP inside a cpp or c file.

So I am not clear of what you are saying

Re: C-function in FWH

Posted: Sat Apr 09, 2016 12:42 pm
by Marc Vanzegbroeck
Here I found the working of fromfiletime.
https://msdn.microsoft.com/nl-be/librar ... -snippet-2
There is a C#,C++,F# and VB example.
Maybe it's easyer to convert it to FWH since its:

Code: Select all

A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC). Windows uses a file time to record when an application creates, accesses, or writes to a file.

Re: C-function in FWH

Posted: Sat Apr 09, 2016 1:06 pm
by byte-one
Mr. Rao, from Antonio above:
Using Borland we can not use C++ code in #pragma BEGINDUMP ... ENDDUMP as we compile in C mode

Re: C-function in FWH

Posted: Sat Apr 09, 2016 1:49 pm
by nageswaragunupudi
Marc Vanzegbroeck wrote:Here I found the working of fromfiletime.
https://msdn.microsoft.com/nl-be/librar ... -snippet-2
There is a C#,C++,F# and VB example.
Maybe it's easyer to convert it to FWH since its:

Code: Select all

A Windows file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC). Windows uses a file time to record when an application creates, accesses, or writes to a file.
Thank you very much.
Once we have this information, it is now extremely simple.
Here is the function for you:

Code: Select all

function DateTimeFromFileTime( nTicks )
return {^ 1601/01/01 00:00:00 } + ( nTicks / 10000000.0 / 86400.0 )
 
test:
? DateTimeFromFileTime( 131032008000002432 ) --> 23-03-2016 10:00:00

Unlike those VB and C# programmers we don't depend on external libraries for simple things like this.

Re: C-function in FWH

Posted: Sat Apr 09, 2016 4:11 pm
by Marc Vanzegbroeck
Rao,

Thank you very much.
I will try it.

Re: C-function in FWH

Posted: Sat Apr 09, 2016 4:36 pm
by Marc Vanzegbroeck
Mr Rao,

It's working fine. :D
Just one question. The result is valtype T.
How can I convert it into a stringtype?
I want to write it into a database with a field of type char.