[Mono-list] Re: [Mono-dev] PInvoke : argument passing by ref

Shankari shankari82 at yahoo.com
Sun Oct 23 00:46:31 EDT 2005


I want to know : After unmanaged code manipulates the
ref object...it copies it BACK to managed memory.
Where does this happen.

Is it in marshal.c:mono_marshal_emit_native_wrapper
??? lines 6022 ??

 /* convert the result  */
        if (!sig->ret->byref) {
                MonoMarshalSpec *spec = mspecs [0];
                type = sig->ret->type;

                if (spec && spec->native ==
MONO_NATIVE_CUSTOM) {
                        emit_marshal (&m, 0, sig->ret,
spec, 0, NULL, MARSHAL_ACTION_CONV_RESULT);
                } else {

                handle_enum:
                        switch (type) {
                        case MONO_TYPE_VOID:
                                break;
                        case MONO_TYPE_I1:
                        case MONO_TYPE_U1:

Thanks

--- Zoltan Varga <vargaz at gmail.com> wrote:

>                                         Hi,
> 
>  The way mono marshalls data from/to native code is
> described here:
> 
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfmarshallingtypes.asp
> 
> 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,
> ie.
> 
> void foo ([In] ref AStruct s).
> 
> This doesn't work in 1.1.9, but it works in the SVN
> version, see this bug:
> 
> http://bugzilla.ximian.com/show_bug.cgi?id=76502
> 
>            Zoltan
> 
> 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
> >
> 



		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs


More information about the Mono-list mailing list