Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FILETIME to __int64

Tags:

c++

int64

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

like image 289
akif Avatar asked Oct 14 '09 14:10

akif


4 Answers

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 );
like image 114
Goz Avatar answered Oct 10 '22 06:10

Goz


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.

like image 17
GManNickG Avatar answered Nov 11 '22 19:11

GManNickG


There is no need to revert to arcane constructs using bitwise OR's. The Windows API has got everything you need to do this.

unsigned __int64    convert( const FILETIME & ac_FileTime )
{
  ULARGE_INTEGER    lv_Large ;

  lv_Large.LowPart  = ac_FileTime.dwLowDateTime   ;
  lv_Large.HighPart = ac_FileTime.dwHighDateTime  ;

  return lv_Large.QuadPart ;
}  

Or if you want to go to __int64 directly.

__int64 convert_to_int64( const FILETIME & ac_FileTime )
{
  return static_cast< __int64 > ( convert( ac_FileTime ) ) ;
}
like image 16
QBziZ Avatar answered Nov 11 '22 18:11

QBziZ


Try

(__int64(filetime.dwHighDateTime)<<32) | __int64(filetime.dwLowDateTime)
like image 7
Martin B Avatar answered Nov 11 '22 17:11

Martin B