Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 10-Aug-10 23:37pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Just to answer my own question Big Grin | :-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 Thumbs Up | :thumbsup:
 
http://softwaredevscott.spaces.live.com/blog/cns!1A9E939F7373F3B7!146.entry?sa=683367813[^]
 

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

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

  Print Answers RSS
0 OriginalGriff 375
1 Richard Deeming 240
2 _Amy 205
3 CHill60 195
4 Nirav Prabtani 178
0 OriginalGriff 8,104
1 Sergey Alexandrovich Kryukov 7,045
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 26 Aug 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100