[Mono-list] How to pass an object as ref or out

Robert Jordan robertj at gmx.net
Thu Apr 17 16:33:18 UTC 2014


On 17.04.2014 16:55, carmack2000 wrote:
> After I followed your code I got this error:
> Unhandled exception at 0x100b8c87 in MonoScriptingTest.exe: 0xC0000005:
> Access violation reading location 0x00000000.
> I'll look into this.
>
> You said 'This is no better than the former non-ref version.' If I want to
> use ref-object to return values (GetPosition), how can I get it ?
>
> C#
> [MethodImplAttribute(MethodImplOptions.InternalCall)]
> public static extern void GetPosition(string name, ref Vector2 o)
>
> C++: still doing like this ?
> void GetPosition(MonoString* ms, MonoObject** mo)
> {
>          Vector2 pos = *(Vector2*)mono_object_unbox(*mo);
>          pos.x = xxxx; // Returned to the caller
>          pos.y = xxxx;
> }

void GetPosition(MonoString* ms, Vector2 *vector)
{
	vector->x = ...
}

It assumes that you have a C/C++ Vector2 declaration
that is fully layout-compatible with the managed version.

Robert




More information about the Mono-list mailing list