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 11-Aug-10 0:37am

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 Sergey Alexandrovich Kryukov 434
1 Maciej Los 430
2 OriginalGriff 315
3 CHill60 240
4 Abhinav S 220
0 Sergey Alexandrovich Kryukov 10,102
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076


Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 26 Aug 2010
Copyright © CodeProject, 1999-2015
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