manipulating LARGE_INTEGERS

和自甴很熟 提交于 2019-12-01 03:09:11

LARGE_INTEGER is a union of a 64-bit integer and a pair of 32-bit integers. If you want to perform 64-bit arithmetic on one you need to select the 64-bit int from inside the union.

LARGE_INTEGER a = { 0 };
LARGE_INTEGER b = { 0 };

__int64 c = a.QuadPart - b.QuadPart;

Here it is:

LARGE_INTEGER x,y;
///
//Some codes...
///

__int64 diff = x.QuadPart - y.QuadPart

Because QuadPart is defined as a LONGLONG , that same as __int64.

LARGE_INTEGER is a union, documented here. You probably want a QuadPart member.

LARGE_INTEGER is a union, you can still use .QuadPart if you want to work on the 64-bit value.

As the Documentation says in the Remarks section :

The LARGE_INTEGER structure is actually a union. If your compiler has built-in support for 64-bit integers, use the QuadPart member to store the 64-bit integer. Otherwise, use the LowPart and HighPart members to store the 64-bit integer.

So if your compiler supports 64 bit integers use quadPart like this :

LARGE_INTEGER a, b;
__int64 diff = a.QuadPart - b.QuadPart

In addition to the answers, if you are looking to construct a LARGE_INTEGER with a value other than zero, you can assign the low and high parts separately. LowPart is first as defined in the union, and the only highPart is signed.

LARGE_INTEGER li = {0x01234567, -1};
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!