C-function in FWH

C-function in FWH

Postby Marc Vanzegbroeck » Fri Apr 08, 2016 11:48 am

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  Expand view
#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;
}
 
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: C-function in FWH

Postby Antonio Linares » Fri Apr 08, 2016 2:37 pm

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C-function in FWH

Postby Marc Vanzegbroeck » Fri Apr 08, 2016 4:25 pm

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.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: C-function in FWH

Postby Antonio Linares » Fri Apr 08, 2016 4:33 pm

Marc,

What C compiler are you using ?

We may try it using a C++ file
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C-function in FWH

Postby Marc Vanzegbroeck » Fri Apr 08, 2016 4:43 pm

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  Expand view
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....
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: C-function in FWH

Postby Antonio Linares » Fri Apr 08, 2016 5:02 pm

Marc,

We need Mr. Rao's advise

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C-function in FWH

Postby Marc Vanzegbroeck » Sat Apr 09, 2016 9:16 am

Antonio,

Is it not possible to use that function with
Code: Select all  Expand view
#pragma BEGINDUMP

like you do with onther C-functions?
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: C-function in FWH

Postby Antonio Linares » Sat Apr 09, 2016 9:33 am

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: C-function in FWH

Postby byte-one » Sat Apr 09, 2016 11:50 am

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
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: C-function in FWH

Postby nageswaragunupudi » Sat Apr 09, 2016 11:57 am

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
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10639
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: C-function in FWH

Postby Marc Vanzegbroeck » Sat Apr 09, 2016 12:42 pm

Here I found the working of fromfiletime.
https://msdn.microsoft.com/nl-be/library/system.datetimeoffset.fromfiletime(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-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  Expand view
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.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: C-function in FWH

Postby byte-one » Sat Apr 09, 2016 1:06 pm

Mr. Rao, from Antonio above:
Using Borland we can not use C++ code in #pragma BEGINDUMP ... ENDDUMP as we compile in C mode
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: C-function in FWH

Postby nageswaragunupudi » Sat Apr 09, 2016 1:49 pm

Marc Vanzegbroeck wrote:Here I found the working of fromfiletime.
https://msdn.microsoft.com/nl-be/library/system.datetimeoffset.fromfiletime(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-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  Expand view
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  Expand view
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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10639
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: C-function in FWH

Postby Marc Vanzegbroeck » Sat Apr 09, 2016 4:11 pm

Rao,

Thank you very much.
I will try it.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: C-function in FWH

Postby Marc Vanzegbroeck » Sat Apr 09, 2016 4:36 pm

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.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], Silvio.Falconi and 40 guests