I have to interface with a C function from C#
The function sends a message over the network.
Here is my working definition in C#:
delegate void SendNetMessageDelegate(uint messageCode, ref MessageData messageData, uint messageSize);
and the MessageData is defined like that:
[StructLayout(LayoutKind.Sequential)]
internal struct MessageData { ... }
those definitions work good so far.
The problem is that sometimes I need to call the same function with another payload.
That means I would have to make another delegate that takes “OtherMessageData” struct instead of “MessageData”
So I would have to add another SendNetMessageDelegate that takes another struct as reference.
Is there an easier way?
So I can call SendNetMessage(messageCode, ref AnyStructHere messageData, messageSize)
I tried changing the parameter type to “object” and then casting my structs to object, but that didn’t work…
How about generics