Mike
Mike

Reputation:

How to create FILETIME in Win32?

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?

Upvotes: 0

Views: 2637

Answers (3)

ralphtheninja
ralphtheninja

Reputation: 133128

__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;

Upvotes: 0

Donnie DeBoer
Donnie DeBoer

Reputation: 2525

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;

Upvotes: 2

George Phillips
George Phillips

Reputation: 4654

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.

Upvotes: 3

Related Questions