Is It possible get ticks number with same format like DateTime.Ticks
.NET object, that is in 100ns units, in C++ ATL or MFC?
Asked
Active
Viewed 1,016 times
3
-
1Add 0x701ce1722770000L to the FILETIME to change the bias from the year 1600 to the year 0. – Hans Passant May 01 '12 at 12:11
1 Answers
2
DateTime.Ticks
does not have any implications on timer resolution, so you are not promised that timer is 100ns accurate. In C++ you have a similar value using:
ULONGLONG nTicks = GetTickCount() * 10000i64;
If you need a more accurate timer, look for QueryPerformanceCounter
based implementation. See:
- How to use QueryPerformanceCounter?
- Fastest timing resolution system
- Can someone decipher whether timeGetTime() or QueryPerformanceCounter/QueryPerformanceFrequency has lower overhead or/and accuracy?
UPD. As for alignment to that from .NET Ticks
property, see comment from Hans above - value casted/calculated from result of GetFileTime
API is also in the same 100 ns units and is set off Ticks
property by a fixed constant.
-
according MSDN GetTickCount() returning ticks count since the system was started. there is ability get ticks since '01/01/0001 00:00:00' like in .NET? – davidb May 01 '12 at 15:12
-
1`GetSystemTimeAsFileTime` http://msdn.microsoft.com/en-us/library/windows/desktop/ms724397%28v=vs.85%29.aspx gets you time in `FILETIME` structure, then you add its values into single 64-bit integer, you add hardcoded constant (see above) and this is what you need. – Roman R. May 01 '12 at 15:19