[Mono-list] Events in embedded Mono?

Andreas Färber andreas.faerber at web.de
Mon Nov 27 03:27:01 EST 2006


Hi Robert,

Am 26.11.2006 um 21:59 schrieb Robert Jordan:

>> 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).

In that case, that would still mean writing a new managed assembly  
just for this purpose.

>> * 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;
> }

Then please add it to SVN! I checked SVN HEAD the weekend and it  
wasn't there.

>> * 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.

I believe I copied the name from the online docs where it's described  
to be necessary for Itanium. If it's not up-to-date someone should  
remove it please or mark it appropriately.

>> * 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.

Again, I got this from the docs.


So, summa summarum the only way is to write managed code that does an  
internal call? No way to directly register such an internal method  
for an event within my native code?

Andreas


More information about the Mono-list mailing list