[Mono-list] Marshaling unmanaged structure

Jonathan Pryor jonpryor at vt.edu
Wed Aug 31 20:52:55 EDT 2005


On Mon, 2005-08-29 at 01:13 -0500, Javier Diaz wrote:
> Hey all
> 
> 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;
> };
> ------------------------------
> 
> Any ideas?

The attached example works for me.

Usage is:

	$ gcc -g -shared -o libunion.so union.c
	$ mcs union.cs
	$ LD_LIBRARY_PATH=`pwd` mono --debug union.exe

 - Jon

-------------- next part --------------
A non-text attachment was scrubbed...
Name: union.c
Type: text/x-csrc
Size: 703 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20050831/dbbdd8f9/union.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: union.cs
Type: text/x-csharp
Size: 730 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20050831/dbbdd8f9/union-0001.bin


More information about the Mono-list mailing list