I'm dealing with a commercial instrumentation DLL that has a C API, so that code can't be changed. We're using DLLIMPORT to use the API routines in C# code. One function takes a pointer to a complex struct, and this one isn't obvious to me whether we can marshal it.
typedef struct eibuf
{
unsigned short buftype;
struct
{
unsigned char etype;
unsigned int edata;
} error[33];
} EIBUF;
My research indicates that the only fixed arrays allowed in C# structs are those with primitive data, so I haven't been able to construct an equivalent data type.
One way to handle this is to create an interface wrapper in C that will flatten the struct out to an array of integer type, which of course can then easily be marshaled from the C# code.
The wrapper function would just declare an EIBUF variable and set all the fields from the array elements, then call the function from the instrumentation API with that. That's kind of our default plan unless there's something more direct that can be done.
Any thoughts?