unsigned short
in C++ is 16 bits whereas
byte
is 8 bits. So you cannot mix and match them and expect everything to work (when you are using pointers). In your C# code, use
ushort
and you should be okay. Here's a quick and dirty untested example:
public ref class MyClass
{
public:
void ProcessBuffer(unsigned short* buffer, int bufferSize)
{
for(int i=0; i<bufferSize; i++)
{
Console::WriteLine(*(buffer + i));
}
}
};
static void Main()
{
MyClass obj = new MyClass();
unsafe
{
int len = 10;
ushort[] buff = new ushort[len];
for (ushort i = 0; i < len; i++)
{
buff[i] = (ushort)(i * 10);
}
fixed (ushort* pBuff = buff)
{
obj.ProcessBuffer(pBuff, len);
}
}
}