OK. Even I don't know if it is the best way, with the help of a colleague of mine I have got a solution, or at least a work-around.
I was not able to find answers to all of my questions, but there is some little progress in understanding the stuff.
I used an
to pass on the byte arraypointer, so the delegate definition is as follows:
public delegate void PFN_DATACALLBACK(IntPtr data, Int16 length);
The DLLImport section works as defined previously.
The Marshalling takes place in my Event (Callback) - Handler:
private static void MyCallback(IntPtr data, Int16 length)
var rxbytes = new byte[length];
Marshal.Copy(data, rxbytes, 0, length);
The approach of using a
could lead to more or less severe troubles due to the string termination NULL characters (0x00, '\0'), which occasionally occur as usual data bytes.
However, it works, if somebody has got a more elegant solution, please don't hesitate to post it.