[Mono-list] accessing struct instance from managed code
Jonathan Pryor
jonpryor@vt.edu
Tue, 01 Mar 2005 07:43:33 -0500
On Mon, 2005-02-28 at 08:16 -0500, Nigel Benns wrote:
> yeah... its basically a GTK+ type of idea.
Then see how Gtk# does things. :-)
> The structure is for ewl_window
> and ewl windows' struct has an EVAS object in it that i can access as
>
> window->evas;
>
> So basically I should wrap this a getter function from C# and make a C
> function that returns the evas addr like this then:
>
> int *ewl_window_evas_get(Ewl_Window *win) {
>
> return win->evas;
>
> };
>
> This is kindof what I wanted to avoid if possible, but if its going to
> cause a whole bunch of Managed -> Unmanaged speghetti any other way, then
> I would rather do it this way. :)
Native wrapper code can be avoided, if you're willing to make a great
number of assumptions, including: compiler structure layout (such as
padding), member sizes, and platform portability (a.k.a. 64-bit clean?).
For example, if a structure contains a "size_t" member, then the size of
that member will vary between 32-bit and 64-bit platforms, so a pure
managed solution would either be: (a) tied to a particular platform, or
(b) insanely ugly as you'd have to have lots of conditional code to
determine whether you're reading a 32-bit or a 64-bit integer.
It can be done, but it would be ugly. Wrapper code is likely far easier
to maintain.
- Jon