FILETIME to __int64

akif picture akif · Oct 14, 2009 · Viewed 18.2k times · Source

What is the proper way to convert a FILETIME structure into __int64? Can you please tell me?

Answer

GManNickG picture GManNickG · Oct 14, 2009

I don't think you're suppose to: "Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows."

Source.

If you really wanted it would be something like:

__int64 to_int64(FILETIME ft)
{
    return static_cast<__int64>(ft.dwHighDateTime) << 32 | ft.dwLowDateTime;
}

FILETIME ft = // ...
__int64 t = to_int64(ft);

But something like:

FILETIME ft = // ...
__int64 t = *reinterpet_cast<__int64*>(&ft);

Is bad.