0

I have a value __int64 that is a 64-bit FILETIME value. FILETIME has a dwLowDateTime and dwHighDateTime. When I try to assign a __int64 to a FILETIME I get a C2440. How do I assign the __int64 to the FILETIME?

Or how do I split the __int64 so that I can assign the low part to dwLowDateTime and the high part to dwHighDateTime?

Ajay
  • 18,086
  • 12
  • 59
  • 105

3 Answers3

3

Here's the basic outline.

__int64 t;
FILETIME ft;

ft.dwLowDateTime = (DWORD)t;
ft.dwHighDateTime = (DWORD)(t >> 32);

NOT RECOMMENDED approach

ft = *(FILETIME *)(&t);

It'll work due to the clever arrangement of FILETIME, but the sacrifice in portability and clarity is not worth it. Use only in times of proven dire need and wrap it in asserts to prove it will work.

George Phillips
  • 4,564
  • 27
  • 25
2

Mike,

You could use a ULARGE_INTEGER struct to copy the __int64 into the FILETIME:

__int64 i64;
ULARGE_INTEGER li;
FILETIME ft;

li.QuadPart = i64;
ft.dwHighDateTime = li.HighPart;
ft.dwLowDateTime = li.LowPart;
Vladimir Panteleev
  • 24,651
  • 6
  • 70
  • 114
Donnie DeBoer
  • 2,517
  • 15
  • 14
0
__int64 i;
FILETIME ft;

// From __int64 to FILETIME

ft.dwHighDateTime = (DWORD)(i >> 32);
ft.dwLowDateTime = (DWORD)(i & 0xFFFFFFFF);


// From FILETIME to __int64

i = (ft.dwHighDateTime << 32) + ft.dwLowDateTime;
PhilLab
  • 4,777
  • 1
  • 25
  • 77
rtn
  • 127,556
  • 20
  • 111
  • 121
  • 1
    The mask should be 0xFFFFFFFF. The second conversion won't work unless you cast ft.dwHighDateTime to __int64 before the << 32. And adding ft.dwLowDateTime might be a problem if DWORD is signed. – George Phillips Jul 08 '09 at 20:13