[Mono-list] Unboxing a MonoObject

Candace Bain Candace_Bain@avid.com
Tue, 10 Jun 2003 15:49:34 -0500


Hello,

I'm putting together a proof-of-concept application that calls from a
C++ command application into a C# class using mono_runtime_invoke.  I
need to be able to return values from the C# calls to my C++ code.
According to the instructions at:

http://www.go-mono.com/embedded-api.html

I need to unbox the MonoObject pointer that mono_runtime_invoke returned
to me to get the return value of the function.  If I'm expecting a
string I've found that the following code will work:

MonoString * str =3D NULL;
gchar *message =3D (char *) "";

....

  str =3D (MonoString *)mono_runtime_invoke (method, test, NULL, NULL);
  if ( str )
    {
      message =3D mono_string_to_utf8(str);
    }

But it's not clear to me how to unbox a MonoObject to get to a bool,
double, or int value.  Thanks in advance for any pointers about how to
do this.

-Candace