I embedded Mono runtime 3.12 in my QT c++ app on Os x 10.8.5 and try to get
generic class in my c++ app.
Case 1:
c#
namespace TestDictionary
{
public class Class1
{
public Dictionarystring,object DictionaryField;
public static void Dump (Dictionary string, object dictionary)
{
Console.WriteLine(Dump called\n);
}
public static void Main()
{
Console.WriteLine(Class1 Main called!\n);
}
}
}
c++
MonoClass* classDictionary = NULL;
classDictionary = mono_class_from_name(image, TestDictionary,
Class1);
I compiled TestDictionary.exe and classDictionary is non-NULL.
Case 2:
c#
namespace TestDictionary
{
public class Class1
{
public Dictionarystring,object DictionaryField;
public static void Dump (Dictionary string, object dictionary)
{
Console.WriteLine(Dump called\n);
}
}
}
namespace Playstkop.Toolbox
{
public class ToolboxFacade
{
public static void Main()
{
Class1 testClass1 = new Class1();
Console.WriteLine(ToolboxFacade Main called!!\n);
}
}
}
c++
MonoClass* classDictionary = NULL;
classDictionary = mono_class_from_name(image, TestDictionary,
Class1);
I compiled TestDictionary.dll and Playstkop.Toolbox.exe. classDictionary
returns NULL. I digged into mono_class_from_name and found that the value of
'name' is 0x0 instead of Class1.
Locals
assembly_idx@0x guint32
buf \235§\013\001\000\000\000... char [1024]
class 0x0 MonoClass *
class@1 0x0 MonoClass *
class@2 @0x10bca9f00MonoClass
cols@0x0guint32 [5]
i @0x int
idx @0x guint32
image @0x10487fe00MonoImage
impl@0x guint32
len @0x int
loaded_image0x0 MonoImage *
module 0x0 MonoImage *
name 0x0 char *
name_space TestDictionarychar *
nested 0x0 char *
nspace_table0x0 GHashTable *
pos @0x int
res @0x gboolean
t 0x0 MonoTableInfo *
token 0 guint32
This is the Locals when 'mono_class_from_name' returns:
Locals
assembly_idx@0x guint32
buf ݯ\013\001\000\000\000@ú\... char [1024]
class 0x0 MonoClass *
class@1 0x0 MonoClass *
class@2 0x0 MonoClass *
cols@0x0guint32 [5]
i @0x int
idx @0x guint32
image 0x0 MonoImage *
impl@0x guint32
len @0x int
loaded_image0x0 MonoImage *
module 0x0 MonoImage *
name0x0 char *
name_space TestDictionarychar *
nested 0x0 char *
nspace_table0x0 GHashTable *
pos @0x int
res @0x gboolean
t 0x0 MonoTableInfo *
token 0 guint32
I go back to Case 1 and trace the method 'mono_class_from_name'. The value
of 'name' is also 0x0 (Surprised!).
Locals
assembly_idx@0x guint32
buf ý§\013\001\000\000@... char [1024]
class 0x0 MonoClass *
class@1 0x0 MonoClass *
class@2 @0x10bcaff00MonoClass
cols@0x0guint32 [5]
i @0x int
idx @0x guint32
image @0x1068a3c00MonoImage
impl@0x guint32
len @0x int
loaded_image0x0 MonoImage *
module 0x0 MonoImage *
name 0x0 char *
name_space TestDictionarychar *
nested 0x0 char *
nspace_table0x0 GHashTable *
pos @0x int
res @0x gboolean
t 0x0 MonoTableInfo *
token 0 guint32
However, when