1

I'm trying to wrap a set of C++ functions and structs based on a header file. So far I think I understand the concepts behind wrapping each structure, but I'm not sure how to pull this one apart:

typedef struct
{
    BYTE    commCode;
    *other stuff*

    struct
    {
        DWORD   size;
        LPBYTE  payload;
    }
    Data;    
}
Set, *CommSet;

Should I do something like this?:

[StructLayout(LayoutKind.Sequential)]
public class Set
{
    public byte commCode;

    public class DATA
    {
        public uint size;
        public byte[] payload;
    }
}

But at this point I'm not sure how to account for the other type, the *CommSet pointer. Do I need a separate structure/class for that?

The Whether Man
  • 362
  • 5
  • 21

1 Answers1

1

This is simply shorthand notation for declaring both the typedef struct and a pointer to it. See here.

In your PInvoke bindings, depending on how it's used, you can use an IntPtr and marshal structs of type Set as required, or use MarshalAs to marshal a pointer pointing to a known length of structures.

Community
  • 1
  • 1
Ani
  • 10,826
  • 3
  • 27
  • 46