[Mono-list] Re: [Mono-dev] PInvoke ques
kornelpal at hotmail.com
Sun Oct 23 07:58:44 EDT 2005
There is no need to modify the runtime to get the behavior you want. You
simply have to use [In()] and [Out()] attributes. Note that however that for
performace reasons there are types in MS runtime as well that are not copied
even if you specify [In()] attribute thus they can be modified in unamanged
code. This behavior is documented in MSDN library.
As such [In()] and [Out()] attributes only tell the runtime that you need in
and/or out mashaling rather than you want to prevent unmanaged code from
modifying you data. If you want to make sure that you prevent unmanaged code
from modifying your data you have to make a copy in managed code before
passing data to unmanaged code. (This is of course only in case of by-ref
----- Original Message -----
From: "Robert Jordan" <robertj at gmx.net>
To: <mono-devel-list at lists.ximian.com>
Cc: <Mono-list at lists.ximian.com>
Sent: Sunday, October 23, 2005 1:28 PM
Subject: Re: [Mono-dev] PInvoke ques
>> My aim is to prevent an update to a pass-by-ref
>> value(this is a part of my work in fault isolation).
>> My idea is to make a copy of the managed type , so
>> this copy will be updated rather than the original
> Well, as Zoltan told you: if the ref parameter is
> marked with the [In] attribute, it won't be marshaled
> back, at least not with SVN head.
>> In order to do this , I need the size of the managed
>> object. Does the instance_size denote the size of the
>> "managed object" ??
> There is no need to reinvent the wheel. The code
> is already there. In order to do this you have to mark
> the parameter with the [In] attribute.
> If you don't want to do this is your C# code, you may
> somehow imply PARAM_ATTRIBUTE_IN to the "attrs" field
> of the parameter. You can do this in emit_marshal_vtype,
> somewhere after "case MARSHAL_ACTION_CONV_OUT".
> Needless to say that you're breaking the runtime's
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
More information about the Mono-list