3

Is It possible get ticks number with same format like DateTime.Ticks .NET object, that is in 100ns units, in C++ ATL or MFC?

Roman R.
  • 68,205
  • 6
  • 94
  • 158
davidb
  • 55
  • 1
  • 7

1 Answers1

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:

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.

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • 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