我試圖從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