473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

struct containing array of pointers to struct (C dll to C#)

17
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.
Nov 19 '07 #1
0 1300

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes)...
2
by: beetle | last post by:
Hello, I'm storing data in several different binary tree's. The root node is located in a struct containing general data about the tree. struct lnode { char *fname; int nentry;
6
by: JS | last post by:
I have this struct: struct pcb { void *(*start_routine) (void *); void *arg; jmp_buf state; int stak; }; These pointers:
4
by: PCHOME | last post by:
Hi! I have questions about qsort( ). Is anyone be willing to help? I use the following struct: struct Struct_A{ double value; ... } *AA, **pAA;
14
by: indigodfw | last post by:
Greetings from India I would like to know the rationale on allowing structs to be assigned (using = operator) and not allowing equality operator ( == operator) on them. The compiler when it...
36
by: Eric Laberge | last post by:
Hi! I'm working on automatically generated code, and need to assign arrays. memcpy is an obvious solution, but it becomes complicated to use in the context I'm working on, ie.: I could use it...
4
by: Michael Brennan | last post by:
I have a menu_item structure containing an union. func is used if the menu item should use a callback, and submenu if a popupmen should be shown. struct menu_item { enum { function, popup }...
18
by: lovecreatesbea... | last post by:
1. The following code snippet uses minus operation on two pointers to calculate the distance between struct members. This is illegal, right? 2. s1 and s2 are type of the same struct S. Can the...
4
by: Sheldon | last post by:
Hi, I have a unique case where I need an array of structs that grows and within this array is another struct that grows in some cases. I'm having trouble allocating memory. Since I have never...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.