1

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?

  • 4
    C / C++ isn't a language, and engineers of each type fight in bars. Do you want to start fights here? I think you should only tag 1 of them – UKMonkey Nov 30 '17 at 12:54
  • `char*` and `char[]` are very different mainly about locality aspect, you can read this to have detail about this aspect https://techtalk.intersec.com/2014/02/more-about-locality/ – Ôrel Nov 30 '17 at 12:58
  • Change byte[] to IntPtr. If you want to have a byte[], then proceed it with a length so the size can be determined. – jdweng Nov 30 '17 at 13:02
  • @Ron I'll add (c) Ron to the next few :) I'd edit that one, but it was too long ago) – UKMonkey Nov 30 '17 at 13:21

0 Answers0