Hi folks!
I have to send and receive data via TCP/IP from a legacy server. The bytes I send and receive are of course representing some data structures. In C/C++ I would memcpy the array into an existing structure or I would just cast a pointer of the strcut type to my byte array. In C it would look something like this:
#pragma pack(push, 1)
typedef struct INNER_ST
{
DWORD A;
BYTE B;
};
typedef struct FOO_ST
{
WORD W;
BYTE X[20];
INNER_ST data[10];
};
#pragma pack(pop, 1)
void ReceiveData(const BYTE *pData)
{
FOO_ST *pFooSt;
pFooSt = (FOO_ST *)pData;
DWORD alpha = pFooSt->data[0].A;
}
In C# my structures would look like this:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct INNER_ST
{
public UInt32 A;
public Byte B;
};
[StructLayout(LayoutKind.Sequential, Pack = 1)]
unsafe struct FOO_ST
{
public UInt16 W;
public fixed Byte X[20];
public fixed INNER_ST data[10];
};
To copy "simmple" structures like INNER_ST with Marshal.PtrToStructure is not the problem.
My question: What can I do with arrays of structures inside structure to solve error CS1663.
Thx for any ideas or hints.
Andy
PS: Of course I cannot change the server side. I have the header files with the structure definitions in C and the new client will be in C#.