Search code examples
c++winapifiletime

I have piece of code that gets duration from a FILETIME struct. What does it mean?


I have this function

void prtduration(const FILETIME *ft_start, const FILETIME *ft_end) 
{
    double duration = (ft_end->dwHighDateTime - ft_start->dwHighDateTime) *
        (7 * 60 + 9 + 496e-3)
        + (ft_end->dwLowDateTime - ft_start->dwLowDateTime) / 1e7;
    printf("duration %.1f seconds\n", duration);
    system("pause");
}

Could anybody explain the working of the following part of the code?

(ft_end->dwHighDateTime - ft_start->dwHighDateTime) *
            (7 * 60 + 9 + 496e-3)
            + (ft_end->dwLowDateTime - ft_start->dwLowDateTime) / 1e7;

Solution

  • 7 is very approximately frequency when FileTime variable changes its value. Namely, every 7 (+-3 or even more) minutes it increases on 1. Than we multiply it on 60 for getting value in seconds.

    9 + 496e-3 - is time is seconds that deals somehow with compilation (from the start of the withdrawal to output in the console) that we are losing.

    Really, it is very bad code and we shouldn't write like this.

    However it have forced me to learn better about FileTime work.

    Thanks everyone for answers, I very appreciate it.