What is the safest way to subtract two System.Runtime.InteropServices.ComTypes.FILETIME objects
Posted
by
Anindya Chatterjee
on Stack Overflow
See other posts from Stack Overflow
or by Anindya Chatterjee
Published on 2011-01-16T18:56:58Z
Indexed on
2011/01/16
19:53 UTC
Read the original article
Hit count: 270
I wonder what is the safest way to subtract two System.Runtime.InteropServices.ComTypes.FILETIME
objects? I used the following code but sometimes it gives me ArithmaticOverflow exception due to the negative number in Low 32-bit values. I am not sure enclosing the body with unchecked
will serve the purpose or not. Please give me some suggestion on how to do it safely without getting any runtime exception or CS0675 warning message.
private static UInt64 SubtractTimes(FILETIME a, FILETIME b)
{
UInt64 aInt = ((UInt64)(a.dwHighDateTime << 32)) | (UInt32)a.dwLowDateTime;
UInt64 bInt = ((UInt64)(b.dwHighDateTime << 32)) | (UInt32)b.dwLowDateTime;
return aInt - bInt;
}
© Stack Overflow or respective owner