[Gtk-sharp-list] binding another libraries
Jonathan Pryor
jonpryor@vt.edu
Wed, 08 Sep 2004 19:39:47 -0400
Strictly speaking, mono-list would be more appropriate for this
question, but I'll answer it anyway.
On Mon, 2004-09-06 at 05:27, juanjo molinero wrote:
<snip/>
> struct EpegImage{
> struct JpegImage image;
> int w;
> int h;
> }
At a minimum, you need to know the size of a JpegImage. This is
unavoidable, but you can get it from your C compiler using a short
program:
printf ("sizeof(JpegImage)=%i\n", sizeof(struct JpegImage));
Once you have the structure size, you just need to tell the runtime
marshaller how large the nested structure is:
[StructLayout(LayoutKind.Sequential, Size=SIZE_FROM_ABOVE)]
struct JpegImage {}
struct EpegImage {
JpegImage ignored;
public int w;
public int h;
}
However, this is non-portable (between 32-bit and 64-bit platforms) if
JpegImage contains pointers (or something else that varies with the
platform, such as intptr_t). As such, it would be preferable to use the
actual declaration of JpegImage, if at all possible, so that you don't
need a managed wrapper library for each target platform.
- Jon