tags:

views:

369

answers:

3

I have a value __int64 that is a 64bit FILETIME value. FILETIME has a dwLowDateTime and dwHighDateTime. When I try to assign a __int64 to a FLIETIME 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?

Thanks!

+1  A: 

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
bit shift... of course.
A: 
__int64 i;
FILETIME ft;

// From __int64 to FILETIME

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


// From FILETIME to __int64

i = (ft.dwHighDateTime << 32) + ft.dwLowDateTime;
Magnus Skog
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
A: 

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;

Donnie DeBoer