How do I make my struct blittable?

1.6k views Asked by At

I'm working with RakNet as a C plugin for C#. I was getting by fine receiving packets as char* and casting them as byte and IntPtr as needed, without complex interop being necessary. However, as a quality of life adjustment, I decided I'd be better off returning a structure containing packet information instead of just the data itself. Despite the structure being rather simple, I can't get it to work:

In C:

typedef struct SmartPacket
{
    unsigned char id;
    unsigned char* data;
    unsigned long long guid;
    char* sysAddress;
}SmartPacket, *PSmartPacket;

In C#:

[StructLayout(LayoutKind.Sequential)]
struct SmartPacket
{
    public byte id;
    public byte[] data;
    public ulong guid;
    public byte[] sysAddress;
};

What am I doing wrong/how do I make this blittable?

0

There are 0 answers