[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mono-list
Subject:    Re: [Mono-list] Marshaling unmanaged structure
From:       Miguel de Icaza <miguel () ximian ! com>
Date:       2005-08-31 13:38:28
Message-ID: 1125495508.7610.177.camel () linux ! site
[Download RAW message or body]


> I have an unmanaged structure that looks like this:
> 
> ------------------------------
> typedef struct event_struct {
>   struct event_struct *next;
>     int type;
>     union {
>        struct ev_levels  levels;
>        struct ev_text text;
>        struct ev_call_state call;
>        struct ev_netstats  netstats;
>        struct ev_url url;
>        struct ev_video video;
>        struct ev_registration reg;
>     } ev;
> } event;
> ------------------------------
> 
> I don't know how to wrap this structure, I know that the only posible
> way us by using the attribute [StructLayout (LayoutKind.Explicit]]
> and the attribute [FieldOffset (..)]
> 
> the structures that are inside the union are easy to wrap, they look like this:
> ------------------------------
> struct iaxc_ev_levels {
>   float input;
>   float output;
> };
> ------------------------------

If I were you, I would define multiple structures, one per union value:

	[StructLayout (Sequential)]
	struct ev_levels_container {
		IntPtr next;
		int type;
		ev_levels level;
	}

And on the caller code, depending on the type value convert a class into
the proper underlying class.

Miguel
_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic