I don't know how to marshall this structure in M开发者_JS百科ono.
typedef struct rib_struct {
rib_used_t used;
rib_status_t status;
rib_role_t role;
uint8_t conf;
rib_dc_t *pending;
pthread_mutex_t mutex;
pthread_cond_t cond;
rib_f_t *props;
} rib_t;
And for example, rib_dc_t
is like:
typedef struct rib_dc_struct {
uint16_t id;
uint8_t min_id;
uint8_t conf;
struct rib_dc_struct *next;
} rib_dc_t;
I don't know how to marshall the pthread structures. And the pointers... should I use IntPtr
or a managed structures? How to mashall the pointer in the last struct to the struct itself?
Thanks in adanvaced
It doesn't come much more ickier than this. You'd be forced to declare the pthread_mutex_t and pthread_cond_t structures as well. Not great, these are implementation details that C# code shouldn't have to bother with. I would recommend you use the [StructLayout(LayoutKind.Explicit)] so you can declare only the members that the C# code needs. You'll have to write a little test program in C/C++ that uses offsetof() to find the member offsets.
The pointers need to be declared as IntPtr. You have to marshal the pointed-to values yourself with Marshal.PtrToStructure(). Not sure how much of this is covered by Mono.
Thanks for the answer Hans. I have finally managed to avoid this structure, so no problem.
There are only some functions left I dont know how to marshall.
int rib_init(rib_callbacks_t *cb, void *data);
rib_callbacks_t is a structure of delegates like this:
[StructLayout(LayoutKind.Sequential)]
internal struct rib_callbacks_t
{
public NewDevConnectedCallback new_dev_connected;
public DevDisconnectedCallback dev_disconnected;
public DcConnectedCallback new_dc_connected;
}
rib_feature_t *rib_register_feature(char *desc);
I should return this method as IntPtr to unmarshall with Marshall.IntPtrToStructure, am i wrong?
rib_feature_t **rib_register_many_features(uint16_t *dev_type, char **desc, int count);
This One I don't know how to marshall. The two ** have broken me :(.
int rib_send(rib_dc_t *dc, const void *msg, size_t len); int rib_recv(rib_dc_t *dc, void *buf, size_t len);
In these ones, I have used [MarshalAs(UnmanagedType.LPArray)]byte[] buf/msg... is this ok?
Regards
精彩评论