[Mono-list] Passing class to c-function
24 Mar 2003 11:06:33 +0100
On Mon, 2003-03-24 at 09:41, Dominik Fretz wrote:
> I know, this isn't a mono-only facing questen, but in the end, it has to
> run on mono.
> I'm currently helping in porting the SWT-Gtk toolkit to C# (comes from
> Ecplips and will be used as gui toolkit in Sharpdevelop to make it run
> on Linux.
> Now we have to pass a C# Object (a class that holds some data) to a
> native function that makes the conversion between the Gtk-Object in
> C-Land and the Managed object from C#.
> I know about gtk-sharp and I've tried to read some code there, but did't
> find a sollution, and we can't use gtk-sharp for now
> We are able to pass C# structs to C. But structs bring in some problems
> (know inheritance, passing by value instead reference).
> Can someone advice me how to pass a C# class to c and use it there for
> reading and writing data from/back to C#?
I never tried it, but I guess PInvoke should handle that without
problems. Just set LayoutKind.Sequential on the class and you can pass
it like a struct to native code.