[Mono-dev] mono-Interop with Native Libraries

Rafael Teixeira monoman at gmail.com
Fri Sep 3 08:13:19 EDT 2010


You can always try to "massage" (kind of parse) the struct as the default
marshalling will pass to your native function, if you don't direct the
process with attributes.

It comes with all types of risks, and is complex, so I *strongly recommend
that you don't go that way*.

The highest risk is that without the [StructLayout(LayoutKind.Sequential)]
the compiler is free to rearrange the order of the fields to make things as
compact as possible but obeying to the alignment requirements of
the architecture, so things vary wildly along time and across
architectures/OSes.

Hope it helps,

Rafael "Monoman" Teixeira
---------------------------------------
"We live in a world operated by science and technology. We have also
arranged things so that almost no one understands science and technology.
This is a prescription for disaster. We might get away with it for a while,
but sooner or later this combustible mixture of ignorance and power is going
to blow up in our faces."
-Carl Sagan


On Fri, Sep 3, 2010 at 5:58 AM, marcus julius <marcusjls at yahoo.com> wrote:
>
> Hi,
>
> I've just started reading about Interop with Native Libraries in C# and
Mono, so before I started doing something I want to ask more experienced
people as a last resort.
>
> I wanna send a managed class (which extends another class, has another
class as a field and some methods) to unmanaged C++ side.
>
> The question is, is there a way to do this without preparing the class for
marshaling using something like these?
>
> [StructLayout(LayoutKind.Sequential)]
> [MarshalAs(UnmanagedType.LPWStr)]
> etc.
>
> Thanks.
>
>
>
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100903/0b30d33e/attachment-0001.html 


More information about the Mono-devel-list mailing list