Hi.
In C dll, there is a struct that contains an array of struct pointers. I do not know how to represent that in C#. That's my problem.
Here is the relevant C code:
[PHP]struct vector
{
uint elem_count;
uint size;
int (*cmp)(const void *, const void *);
void *table;
};
typedef struct vector VECTOR;
#define CTABLE VECTOR
#define CSTATS VECTOR
struct cstream
{
int mode;
int byte_count;
uchar *buff;
int buff_len;
int buff_pos;
int bit_pos;
bool growable;
bool prepared;
CTABLE *table[2];
CSTATS *stats[3];
uchar last_mode;
int last_mode_offset;
};[/PHP]
And here is the C# code:
[PHP] [UnmanagedFunctionPointer(CallingConvention.Winapi)]
unsafe public delegate int cmp(IntPtr a, IntPtr b);
[StructLayout(LayoutKind.Sequential, Pack = 1)]
unsafe public struct VECTOR
{
public uint elem_count;
public uint size;
public uint elem_size;
[MarshalAs(UnmanagedType.FunctionPtr)]
public cmp cp; //C-func: public int (*cmp)(const void *, const void *);
public IntPtr table;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
unsafe public struct CSTREAM
{
public int mode;
public int byte_count;
public IntPtr buff;
public int buff_len;
public int buff_pos;
public int bit_pos;
public bool growable;
public bool prepared;
public VECTOR[2]; // CTABLE *table[TTABLE_COUNT];
public VECTOR[3]; // CSTATS *stats[STATS_COUNT];
public byte last_mode;
public int last_mode_offset;
}
[DllImport("compr.dll")]
public static extern IntPtr screate(); // this function in C dll returns pointer to struct
[DllImport("compr.dll")]
public static extern IntPtr tcreate(); // this function in C dll returns pointer to struct;[/PHP]
Now, I know how to get the IntPtr to a struct. For example:
[PHP]MyClass.VECTOR stext = new MyClass.VECTOR();
IntPtr st = MyClass.screate();
stext = (MyClass.VECTOR)Marshal.PtrToStructure(st, typeof(MyClass.VECTOR));[/PHP]
However, I do not know how to represent, or work with, "CTABLE *table[2];" or "CSTATS *stats[3];" from my struct in C, in my C# struct (CSTREAM).
I'd appreciate any help.