typedef union _Value {
signed char c;
unsigned char b;
signed short s;
unsigned short w;
signed long l;
unsigned long u;
float f;
double *d;
char *p;
} Value;
typedef struct _Field {
WORD nFieldId;
BYTE bValueType;
Value Value;
} Field;
typedef struct _Packet {
WORD nMessageType;
WORD nSecurityType;
BYTE bExchangeId;
BYTE bMarketCenter;
int iFieldCount;
char cSymbol[20];
Field FieldArr[1];
} Packet;
What are the C# equivalent of these C++ structs?
I am migrating some code from C++ to C# and having problems to migrate these structures. I had tried a few things but I always ended up having marshalling problems.
I’m assuming the ‘char’ is being used as an 8 bit number, if so, then here are you’re mappings:
With this info it should be relatively easy to translate those strucutres (just make sure you keep them as a struct and give it the attribute “[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]”, which will make sure that the marshaller keeps all the data in the same order.
Also, I recommend looking through both the classes and attributes in System.Runtime.InteropServices as they do provide quite a few methods for automating marshaling of data to c/c++ code (and it doesn’t require “unsafe” c# code either).