[Mono-list] Problem with DateTime class from C code
Robert Jordan
robertj at gmx.net
Sat Oct 23 04:59:45 EDT 2010
On 23.10.2010 07:12, Fede wrote:
> Hi!
>
> I've a problem when instantiating a DateTime class from C code and invoking
> the ToString() method.
> The code I've is as follows:
>
> class = mono_class_from_name(mono_get_corlib(), "System", "DateTime");
> object = mono_object_new(domain, class);
> method = mono_class_get_method_from_name(class, "ToString", 0);
> string = (MonoString*)mono_runtime_invoke(method, object, NULL, NULL);
> printf("%s\n", mono_string_to_utf8(string));
>
> It ouputs: 1/1/0001 12:00:03 AM
> when the same C# code (Console.WriteLine(new DateTime().ToString()))
> outputs: 1/1/0001 12:00:00 AM
>
> What am I doing wrong?
You're not invoking a constructor on the DateTime instance.
Assuming you want the default ctor, you can invoke it with:
mono_runtime_object_init (object);
Other non-default ctors need to be mono_runtime_invoked like
any other method.
RObert
More information about the Mono-list
mailing list