如何声明LARGE_INTEGER在C# [英] How to declarate LARGE_INTEGER in C#

查看:274
本文介绍了如何声明LARGE_INTEGER在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码(C ++)是我想转换成C#

the code below(in C++) is what I am trying the convert into C#

DWORD Func_X_4(DWORD arg1, DWORD arg2, DWORD arg3)
{
LARGE_INTEGER result = {1, 0};
LARGE_INTEGER temp1 = {0};
LARGE_INTEGER temp2 = {0};
LARGE_INTEGER temp3 = {0};
LARGE_INTEGER temp4 = {0};
for(int x = 0; x < 32; ++x)
{
	if(arg2 & 1)
	{
		temp1.LowPart = arg3;
		temp1.HighPart = 0;
		temp2.QuadPart = temp1.QuadPart * result.QuadPart;
		temp3.LowPart = arg1;
		temp3.HighPart = 0;
		temp4.QuadPart = temp2.QuadPart % temp3.QuadPart;
		result.QuadPart = temp4.QuadPart;
	}
	arg2 >>= 1;
	temp1.LowPart = arg3;
	temp1.HighPart = 0;
	temp1.QuadPart *= temp1.QuadPart;
	temp2.LowPart = arg1;
	temp2.HighPart = 0;
	temp3.QuadPart = temp1.QuadPart % temp2.QuadPart;
	arg3 = temp3.LowPart;
	if(!arg2)
		break;
}
return result.LowPart;
}

下面我试着翻译代码,但它是太乱了,我从来没有工作与前大整数

Here I tried to translate the code,but it's too messy and I never worked with Large integers before.

结构:

public struct LARGE_INTEGER
{
    UInt32 LowPart;
    Int32 HighPart;
    Int32 QuadPart;
}



翻译功能:

Translated function:

    public Int32 Func_X_4(Int32 arg1, Int32 arg2, Int32 arg3)
    {
	LARGE_INTEGER result = {1, 0}; //this and the four below,are they correct?
	LARGE_INTEGER temp1 = {0, 0};
	LARGE_INTEGER temp2 = {0, 0};
	LARGE_INTEGER temp3 = {0, 0};
	LARGE_INTEGER temp4 = {0, 0};
	for(int x = 0; x < 32; ++x)
	{
		if(arg2 & 1==0) //correct?
		{
			temp1.LowPart = arg3;
			temp1.HighPart = 0;
			temp2.QuadPart = temp1.QuadPart * result.QuadPart;
			temp3.LowPart = arg1;
			temp3.HighPart = 0;
			temp4.QuadPart = temp2.QuadPart % temp3.QuadPart;
			result.QuadPart = temp4.QuadPart;
		}
		arg2 >>= 1;
		temp1.LowPart = arg3;
		temp1.HighPart = 0;
		temp1.QuadPart *= temp1.QuadPart;
		temp2.LowPart = arg1;
		temp2.HighPart = 0;
		temp3.QuadPart = temp1.QuadPart % temp2.QuadPart;
		arg3 = temp3.LowPart;
		if(arg2 != 0) //correct?
		break;
	}
	return result.LowPart;
}



问题:
的第一个问题是,我还没有找到在C#中LARGE_INTEGER类型的变量,所以我创建了一个strucure,我想知道,如果确实有。
至于第二个问题,功能是不正确的,毫无效果。

Problems: The first problem is that I haven't found a LARGE_INTEGER type variable in C#,so I created a strucure,I'd like to know if there is actually. As for the second problem,the function is not right,nothing worked.

在那个特定的问题,任何帮助将greatfuly感激!
预先感谢您

Any help on that particular question will be greatfuly appreciated! Thank you in advance.

推荐答案

在LARGE_INTEGER结构的直接翻译应该是:

A direct translation of the LARGE_INTEGER structure would be:

[StructLayout(LayoutKind.Explicit, Size=8)]
struct LARGE_INTEGER
{
    [FieldOffset(0)]public Int64 QuadPart;
    [FieldOffset(0)]public UInt32 LowPart;
    [FieldOffset(4)]public Int32 HighPart;
}



这就像一个工会C,其中 QuadPart 是一个8字节的值,用 LowPart 占据了前4个字节和 HighPart 占据高4个字节。

It's like a union in C, where QuadPart is an 8-byte value, with LowPart occupying the first 4 bytes and HighPart occupying the high 4 bytes.

这篇关于如何声明LARGE_INTEGER在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆