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."
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
2009-10-14 14:30:39
I was in process of editing :)
GMan
2009-10-14 14:36:28
How about memcpy(<__int64>, ? Is it safe?
hab
2009-10-14 15:42:22
I would find `memcpy` harder to understand, but I'm sure it would work. The compiler can probably optimize shift and or better.
GMan
2009-10-14 15:51:22
Indeed, it was harder to understand, but it has worked so far :) Thanks
hab
2009-10-15 04:35:53
+1
A:
Try
(__int64(filetime.dwHighDateTime)<<32) | __int64(filetime.dwLowDateTime)
Martin B
2009-10-14 14:33:14
+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
2009-10-14 14:48:22