[Mono-list] Events in embedded Mono?
Robert Jordan
robertj at gmx.net
Sun Nov 26 15:59:36 EST 2006
Andreas Färber wrote:
> How does one react to managed events in native code?
>
> One possibility I thought of was writing and loading managed code
> with a dispatcher method that p/invokes "__Internal".
This would work only with p/invoke compatible signatures.
If you need to handle signatures with object parameters,
an internal call is required (and it works perfectly, BTW).
> * There is no mono_class_event_from_name function.
> (so I would have to iterate over all events myself - maybe a hint
> that this is not (widely) used yet?)
I'm using this method:
MonoEvent *
mono_class_get_event_from_name (MonoClass *clazz, const char *name)
{
gpointer iter;
MonoEvent *e;
while (clazz) {
iter = NULL;
while ((e = mono_class_get_events (clazz, &iter))) {
if (strcmp (name, mono_event_get_name (e)) == 0)
return e;
}
clazz = mono_class_get_parent (clazz);
}
return NULL;
}
> * There is a mono_create_ftnptr function for converting a function
> pointer into a form always usable by Mono.
> (but what is the expected function signature? is there a this-pointer
> preceding the arguments like in JNI?)
mono_create_ftnptr () doesn't exist, so you probably meant
mono_delegate_to_ftnptr (). This method is the low level
(and internal) counterpart of NET 2.0's
Marshal.GetFunctionPointerForDelegate ().
It works only for P/Invoke signatures, i.e. the signature
can't contain objects.
> * mono_delegate_ctor has a gpointer addr parameter "pointer to native
> code" but also expects a MonoObject* "target object".
> (what's that supposed to be? can/should it be NULL? or is it not
> intended to be used that way?)
mono_delegate_ctor () is internal and, depending on the OS,
already unavailable since a couple of Mono releases.
Robert
More information about the Mono-list
mailing list