views:

131

answers:

4

I marshalled correctly to:

IntPtr buffer

Buffer is pointer to array of 2 pointers to arrays with respective data. The problem is that I get not accurate data, like if there's something missing in the data retrieved (e.g. missimg samples from stream of audio data).

// length is parameter
IntPtr[] temp = new IntPtr[2];
Marshal.Copy(buffer, temp, 0, 2);
bufferedData = new byte[bufferSize];
byte[] a = new byte[length];
byte[] b = new byte[length];
Marshal.Copy(temp[0], a, 0, length);
Marshal.Copy(temp[1], b, 0, length);

edit: sorry I forgot to write those 2 lines :)

A: 

Yes, you would need to copy the byte buffers too :)

Update: That looks better!

leppie
A: 

If buffer is a pointer to an array, you would need to read the pointer once more.

Effectively:

buffer = Marshal.ReadIntPtr(buffer);
leppie
well, thanks for answer, but that was really out. I do get real data, but, it's like there are some missing. Address of the start of an array doesn't help me much with marshalling but pointer does (as showed in my code above).
A: 

Hi, I don't know anything about C# so this is a complete guess, but - you seem to be copying from ints to bytes, is "length" the count in ints, or the count in bytes? Could there be a mixup there? This can be a problem in regular old C++ sometimes.

MrZebra
well, the problem is that everything is in bytes (even length). The only thing that I can think of, is that DLL is sending me wrong data (or not enough data)
+1  A: 

I finally solved it. I wasn't reading full input buffer by mistake. Thanks for all your help!