[Mono-dev] PInvoke : argument passing by ref

Zoltan Varga vargaz at gmail.com
Sat Oct 22 23:55:38 EDT 2005


 The way mono marshalls data from/to native code is described here:


If things don't work that way in mono, than it is a bug and we will fix it.

If you pass structures to native code using 'ref', then you can use
the [In, Out]
attributes to specify whenever changes made in native code are visible
to managed code,

void foo ([In] ref AStruct s).

This doesn't work in 1.1.9, but it works in the SVN version, see this bug:



On 10/23/05, Shankari <shankari82 at yahoo.com> wrote:
> Hello,
> I am trying to isolate the updates by unmanaged code
> if the arguments are passed by reference in Pinvoke.
> I looked up marshal.c and at
> mono_marshal_emit_native_wrapper , the by-ref
> argumments are being marshalled back to managed
> memory.
> I am trying to do this by the foll :
> After the C code has made the updates : when the
> results are being marshalled back to the managed
> object, I can copy this to a diff location  and return
> this address and thus prevent the original argument
> from being updated.
> I could do this at call time , by copying the managed
> structure to another location and passing this
> addr...and this can get updated..but in this case I
> have to change the final byref argument to point to
> this new address.
> Everything leads to mono_mb_emit_byte( where some copy
> actually seems to be happening..) but it emits IL code
> and it *seems* to be pushing similar stuff if I pass
> by value or by reference.
> Any pointers on how to achieve my objective ??
> Thanks,
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

More information about the Mono-devel-list mailing list