Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

Convert long int to filetime?

Posted on 1999-07-14
Medium Priority
1,870 Views
I have used GetSystemTime, SystemTimeToFileTime and systemint = (systemfiletime.dwHighDateTime << 32) +  systemfiletime.dwLowDateTime;
Now I want to subtract sevendays and then convert it to FILETIME again. How do I do that??
0
Question by:bert1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 9
• 9

LVL 22

Accepted Solution

nietod earned 120 total points
ID: 1199998
You can subtract 7 days by converting 7 days to 100s of nanoseconds.   A nanosecond is 1/100,000th of a second, so a 100 nanoseconds is 1/1000th of a second.  I'll call 1/1000th of a second a filetime unit. Thus 7 days is

7days * 24Hours/day * 60 Minutes/Hour * 60 seconds/minute * 1000 filetimeunits/second

so the amount you want to subtract is 7*24*60*60*1000.

continues
0

LVL 22

Expert Comment

ID: 1199999
Then to convert it back to a file time, use
FILETIME FT;

FT.dwLowDateTime = (DWORD) systemint & 0xFFFFFFFF;
FT.dwHighDataTime = (DWORD) ((systemint >> 32) & 0xFFFFFFFF);
0

Author Comment

ID: 1200000
What does (systemint >> 32 ) mean?
Every byte above 32 bytes?

Thanks!
0

LVL 22

Expert Comment

ID: 1200001
No, shift the 64 bit value in systemtime to the "right"  (shift toward low bits) by 32 bits.  Thus the high 32 bits become the low 32 bits and the previous low 32 bits are lost.
0

Author Comment

ID: 1200002
Hmm I dont get the right year back ... can it be beacuae I have:
long int systemint; ?? What should it be (I want a 64 bit integer)
0

Author Comment

ID: 1200003
In other words I need a LARGE_INTEGER...
0

LVL 22

Expert Comment

ID: 1200004
What compiler are you using?

Try "__int64".   That is what VC uses.
0

Author Comment

ID: 1200005
Borland C++ 5.02, well it seem that I have to convert LARGE_INTEGER to FILETIME , it says so in the help file. Im sorry for not knowing that until now :-\

Â·Copy the resulting FILETIME structure to a LARGE_INTEGER structure.
Â·Use normal 64-bit arithmetic on the LARGE_INTEGER value.

0

LVL 22

Expert Comment

ID: 1200006
a regular 64 bit integer would be more direct.

LARGE_INTEGER is a union of a 64-bit integer and 2 32-bit integers.  you would use it like.

LARGE_INTEGER LI;

LL.LowPart = FT.dwLowDateTime;
LL.HighPart = FT.dwHighDateTime;
FT.dwLowDateTime = LL.LowPart;
FT.dwHighDateTime = LL.HighPart;

0

Author Comment

ID: 1200007
Yes thought so too ... but it says:
'LowPart' is not a member of '_LARGE_INTEGER' and
'HighPart' is not a member of '_LARGE_INTEGER'

Do I have to make my own data type LARGE_INTEGER or? It finds QuadPart but not LowPart and HighPart ... :(

why doesnt things work the way I want it :P

Thanks!
0

LVL 22

Expert Comment

ID: 1200008
The LARGE_INTEGER union uses an embedded annonymous structure.  It appears like that may cause a problem just like you are having with other compilers.  (I'm not sure if that is considered legal or illegal by the C++ standard.)  They seem to have a sort of patch where they give the large integer's strucuture the nane "u", so try placing a "u." before the lowpart and highpart.
0

Author Comment

ID: 1200009
Yes that worked , but it seems like I dont have acces to QuadPart at the same time as u.LowPart and u.HighPart ... ill try to get it to work!

Thanks alot!
0

LVL 22

Expert Comment

ID: 1200010
what do you mean by I dont have acces to "QuadPart at the same time as u.LowPart and u.HighPart"
0

Author Comment

ID: 1200011
I got it to work ... I had declared an integer that was to smal to hold the information :-\.

I have an other error that reminds on this one with, if you want you can check my other question.

Where did you get the information about the u.LowPart ?
0

LVL 22

Expert Comment

ID: 1200012
What other question?  what is its ID?   (right above the question box there is a line that will end with Q.XXXXXX.   The XXXXX number identifies the question)

The "u" is undocumented.  I looked for the structure definition in the windows include files.  It was there.  The structure appears in multiple forms using conditional compilation (#ifdef's).  I just guessed that the form with the "u" was being used.
0

Author Comment

ID: 1200013
Ok thanks!

This is the question that I cant get to work ... I would be very pleased if you could help me there.

It's about how to start a function after the main window has been setup and is visible.
ID: Q.10179191
0

LVL 22

Expert Comment

ID: 1200014
I don't think I can help there.  I don't know OWL.   I would avoid using timers as Alex suggests, though.  You don't know how long to wait.   Your best bet is to take action the first time the window is painted.
0

Author Comment

ID: 1200015
Oki.

The problem is that I cant find that action :-l ... i'll have to look some more ... cause there have to be one.
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their waâ€¦
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on thâ€¦
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month5 days, 13 hours left to enroll