Click here to Skip to main content
15,911,646 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Compiler Warning C4373 about virtual methods Pin
George_George26-Feb-08 15:13
George_George26-Feb-08 15:13 
GeneralRe: Compiler Warning C4373 about virtual methods Pin
Rajkumar R26-Feb-08 19:24
Rajkumar R26-Feb-08 19:24 
GeneralRe: Compiler Warning C4373 about virtual methods Pin
George_George26-Feb-08 21:18
George_George26-Feb-08 21:18 
GeneralCasting ULARGE_INTEGER as FILETIME Pin
Ben Aldhouse25-Feb-08 2:07
Ben Aldhouse25-Feb-08 2:07 
GeneralRe: Casting ULARGE_INTEGER as FILETIME Pin
David Crow25-Feb-08 2:19
David Crow25-Feb-08 2:19 
GeneralRe: Casting ULARGE_INTEGER as FILETIME Pin
Ben Aldhouse25-Feb-08 3:10
Ben Aldhouse25-Feb-08 3:10 
QuestionRe: Casting ULARGE_INTEGER as FILETIME Pin
David Crow25-Feb-08 3:53
David Crow25-Feb-08 3:53 
GeneralRe: Casting ULARGE_INTEGER as FILETIME Pin
Ben Aldhouse25-Feb-08 5:02
Ben Aldhouse25-Feb-08 5:02 
I was trying to find the difference between a file's creation date, the current time and get the resulting data in a useful format. Doing this I was aware of the following warning from the MSDN library

Remarks
    It is not recommended that you add and subtract values from the SYSTEMTIME 
    structure to obtain relative times. Instead, you should 

    -Convert the SYSTEMTIME structure to a FILETIME structure. 
    -Copy the resulting FILETIME structure to a ULARGE_INTEGER structure. 
    -Use normal 64-bit arithmetic on the ULARGE_INTEGER value. 


However, I think at this point I was put off because the promised 'HighPart' and 'LowPart' members of ULARGE_INTEGER didn't appear in the autocomplete list on my editor. I have since written in the members anyway and found that they work without any trouble.

Since your last reply I have had a walk around the block and had another look at the code. I discovered that when I was removing some lines whilst taking out the code that used that (FILETIME *)&ULARGE_INTEGER cast, I removed one line I should have left in and edited and left in another line towards the end of the code that should have been removed...

Here is the (now, at last) working code with comments.

Thanks for your encouragement and for showing an interest,

Ben

	WIN32_FIND_DATA FindFileData;
	HANDLE hFind;
	hFind = FindFirstFile(strPath, &FindFileData);
	CString strYears, strMonths, strDays;

	SYSTEMTIME stNow; 
	
//The current time is aquired and stored in SYSTEMTIME format
	GetSystemTime(&stNow);

//The creation time of the file in question is obtained and
//stored in FILETIME format
	const FILETIME  ftFile = FindFileData.ftCreationTime;

//A reference to the current time in FILETIME format is created
	FILETIME ftNow;
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind;
	hFind = FindFirstFile(strPath, &FindFileData);
	CString strYears, strMonths, strDays;

	SYSTEMTIME stNow; 
	
//The current time is aquired and stored in SYSTEMTIME format

	GetSystemTime(&stNow);
	
//The creation time of the file in question is aquired in a FILETIME
//structure then converted inta a SYSTEMTIME structure

	const FILETIME  ftFile = FindFileData.ftCreationTime;
	FILETIME ftNow;
	SystemTimeToFileTime (& stNow, &ftNow);

//The contents of the FILETIME versions of the current time
//and the creation time of the file are now stored in 
//ULARGE_INTEGER structures

	ULARGE_INTEGER ulNowTime, ulFileTime, ulAge;
	ulNowTime.HighPart = ftNow.dwHighDateTime;
	ulNowTime.LowPart = ftNow.dwLowDateTime;
	ulFileTime.HighPart = ftFile.dwHighDateTime;
	ulFileTime.LowPart = ftFile.dwLowDateTime;

//The difference between the current time and the creation time
//of the file can now be created

	ulAge.HighPart = ulNowTime.HighPart - ulFileTime.HighPart;
	ulAge.LowPart = ulNowTime.LowPart - ulFileTime.LowPart;
	
	FILETIME ftAge;
	SYSTEMTIME stAge;

//The ULARGE_INTEGER data can then be copied back to a FILETIME
//structure, this can then be converted to SYSTEMTIME
//which is the convenient format we want our data to be in....

	ftAge.dwHighDateTime = ulAge.HighPart;
	ftAge.dwLowDateTime = ulAge.LowPart;

	FileTimeToSystemTime(&ftAge,&stAge);
	// not SystemTimeToFileTime(&stAge,&ftAge);!

	strYears.Format("%d", stAge.wYear-1601);
	strMonths.Format("%d",stAge.wMonth-1);
	strDays.Format("%d",stAge.wDay-1);

QuestionRe: Casting ULARGE_INTEGER as FILETIME Pin
David Crow25-Feb-08 5:09
David Crow25-Feb-08 5:09 
GeneralRe: Casting ULARGE_INTEGER as FILETIME Pin
Ben Aldhouse25-Feb-08 8:37
Ben Aldhouse25-Feb-08 8:37 
GeneralTo sort shortcut menus programmatically [modified] Pin
Mushtaque Nizamani25-Feb-08 0:49
Mushtaque Nizamani25-Feb-08 0:49 
GeneralRe: To sort shortcut menus programmatically Pin
Iain Clarke, Warrior Programmer25-Feb-08 2:17
Iain Clarke, Warrior Programmer25-Feb-08 2:17 
GeneralRe: To sort shortcut menus programmatically Pin
David Crow25-Feb-08 2:43
David Crow25-Feb-08 2:43 
QuestionHow to restore dialog? Pin
sheetal_0625-Feb-08 0:47
sheetal_0625-Feb-08 0:47 
AnswerRe: How to restore dialog? Pin
David Crow25-Feb-08 2:52
David Crow25-Feb-08 2:52 
GeneralRe: How to restore dialog? Pin
sheetal_0627-Feb-08 17:44
sheetal_0627-Feb-08 17:44 
QuestionRe: How to restore dialog? Pin
David Crow28-Feb-08 2:35
David Crow28-Feb-08 2:35 
AnswerManifest for UAC, how to? (VC2005) [Solved] Pin
Maxwell Chen24-Feb-08 23:49
Maxwell Chen24-Feb-08 23:49 
QuestionRe: Manifest for UAC, how to? (VC2005) Pin
Maxwell Chen25-Feb-08 3:15
Maxwell Chen25-Feb-08 3:15 
QuestionGet Client Request Ip Pin
mirtu24-Feb-08 23:15
mirtu24-Feb-08 23:15 
AnswerRe: Get Client Request Ip Pin
Maruf Maniruzzaman24-Feb-08 23:49
Maruf Maniruzzaman24-Feb-08 23:49 
AnswerRe: Get Client Request Ip Pin
Rajkumar R25-Feb-08 3:16
Rajkumar R25-Feb-08 3:16 
QuestionDefine tree item map ( stl ) ... What wrong with my code ? Pin
Yanshof24-Feb-08 21:57
Yanshof24-Feb-08 21:57 
AnswerRe: Define tree item map ( stl ) ... What wrong with my code ? Pin
Christian Graus24-Feb-08 22:03
protectorChristian Graus24-Feb-08 22:03 
GeneralRe: Define tree item map ( stl ) ... What wrong with my code ? Pin
Yanshof24-Feb-08 22:07
Yanshof24-Feb-08 22:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.