我试图从C++转换代码到c#..但我卡住了。 有人可以让我知道我错了吗?将一段代码从C++转换为c#
C++代码:
void CALLBACK Test(void *buffer, DWORD length)
{
BYTE *b=(BYTE*)buffer, temp[20000];
DWORD p=0;
while (p<length)
{
DWORD c=min(length-p, sizeof(temp));
memcpy(temp, b+p, c);
c=SendData(dummy, temp, c);
if (c==-1) break;
p+=c;
}
}
where is SendData(int, byte[], int)
和电流C#代码
void Test(IntPtr buffer, int length)
{
byte[] temp = new byte[20000];
byte[] b = new byte[length];
Marshal.Copy(buffer, b, 0, length);
long p=0;
while (p<length)
{
long c=Math.Min(length-p, 20000);
Array.Copy(temp, b+p, c);
c=SendData(dummy, temp, (int)c);
if (c==-1) break;
p+=c;
}
}
我不知道做了我正确的做了,但我可以看到我不能申请运营商+
到b+s
,因为它是long
和byte[]
。
感谢
而不是做一个“文字”转换,你不认为这是更好的看看这个函数做什么,并重新在C#中做? – 2011-12-21 21:45:42