[Mono-dev] Embedded mono; getting in C a pointer from an IntPtr object

Jean-Michel.Perraud at csiro.au Jean-Michel.Perraud at csiro.au
Mon Feb 18 10:46:54 UTC 2013


Hi,

I have a scenario where some C function is getting a MonoObject (*pobj) that happens to be an IntPtr. As the native pointer is known to be of a certain native type (SEXP), how do I retrieve it? I tried a few things, the latest being:

	type_il = mono_type_get_type(mono_class_get_type(mono_object_get_class(pobj)));
	switch(type_il)  /*MonoTypeEnum*/
	{
	case MONO_TYPE_I          	: // IntPtr, that we assume to be a SEXP as coming from R.NET.					result = (SEXP)(void*)mono_object_unbox(rclr_mono_call_inst_method("ToPointer", pobj, NULL, 0));
		break;

I soon get an access violation not long after the function return.

I have a working solution when hosting the Microsoft CLR but this is not directly transferable to Mono given the significantly different APIs.

Regards


More information about the Mono-devel-list mailing list