c++windowssystem-clock

Similar functionality to CLOCK_MONOTONIC in Windows (and Windows Embedded CE)


I have some C++ Windows code which needs to compute time intervals. For that, it uses GetCurrentFT if it detects that is running in WinCE and GetSystemTimeAsFileTime for other Windows platforms. However, if I'm not mistaken, this might be vulnerable to system clock manipulations (i.e. someone changing the system clock would make the measured time intervals unreliable).

Is there something similar to UNIX's CLOCK_MONOTONIC for these platforms (both WinCE and the other Windows platforms) which would make use of a monotonically increasing counter and not the system clock?


Solution

  • I did end up using GetTickCount(), which worked just fine.

    As per Microsoft's documentation:

    The number of milliseconds that have elapsed since the system was started indicates success.

    It is a monotonic counter, which is what I was looking for. The granularity of the returned value depends on the hardware, but seems to be enough for my purposes in the hardware I'm using.