tags:

views:

688

answers:

3

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

+2  A: 

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.

GMan
I was in process of editing :)
GMan
How about memcpy(<__int64>, ? Is it safe?
hab
I would find `memcpy` harder to understand, but I'm sure it would work. The compiler can probably optimize shift and or better.
GMan
Indeed, it was harder to understand, but it has worked so far :) Thanks
hab
+1  A: 

Try

(__int64(filetime.dwHighDateTime)<<32) | __int64(filetime.dwLowDateTime)
Martin B
+1  A: 

Of course you could just pass in an __int64 casted to a filetime as follows *(FILETIME*)&int64Val. This will work fine under Visual C++.

ie

__int64 createTime = 0;
__int64 accessTime = 0;
__int64 writeTime = 0;
GetFileTime( hFile, *(FILETIME*)&createTime, *(FILETIME*)&accessTime, *(FILETIME*)&writeTime );
Goz