Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to retrieve the LastWrite time from the Registry key that stores USB mounted device information and I'm having problems with the conversion to DateTime.

I am using the RegQueryInfoKey[^] API and my code to retireve a DateTime object is:

 // override RegQueryInfoKey. lpftLastWriteTime represented by int array
queryInfoKey = RegQueryInfoKey(hSubKey, null, null, IntPtr.Zero,
                ref lpcSubKeys, null, null, ref lpcValues, null, null, null, lpftLastWriteTime);
// subtract the high datetime form the low datetime. low datetime is negative
long lastWriteTime = (((long)lpftLastWriteTime[1]) << 32) + (long)lpftLastWriteTime[0];
                
// convert long to DateTime object
DateTime lastWrite = DateTime.FromFileTime(lastWriteTime);


However, this code does not return the correct LastWrite time in every case.

Can someone shed a bit of light on this?

Thanks


Shockmeister.
Posted

1 solution

Just to answer my own question :-D , the problem lies with the definition of the FILETIME structure. The Win32 structure uses DWORD members, which are UNSIGNED, whereas the .NET Framework type uses SIGNED ints.

See this article for more information :thumbsup:

http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!146.entry?sa=683367813[^]


I'm suprised no one has come across this problem before!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900