[Mono-list] Mono Embedding: manage events
Robert Jordan
robertj at gmx.net
Tue Apr 1 13:02:14 EDT 2008
Ing. Francesco Carsana wrote:
> I'm writing a C++ class with Mono embedding.
> This class is a wrapper to a .NET assembly that
> raises 3 events.
> I would like to know if it's possible to catch
> that events in C++ without changing .NET assembly
> (I haven't assembly source code...).
> Where can I find a code example?
> I've searched in
>
> http://anonsvn.mono-project.com/viewcvs/trunk/mono/samples/embed/
>
> but I haven't found an example on how to manage events...
The recommended way is to declare the handlers as icalls in
managed code:
C#:
class EventHelper
{
// handler of System.EventHandler
[MethodImpl (MethodImplOptions.InternalCall)]
public static extern void EventHandlerICall (object sender,
EventArgs e);
}
C++:
mono_add_internal_call ("EventHelper::EventHandlerICall",
&icall_EventHelper_EventHandlerICall);
void
icall_EventHelper_EventHandlerICall (MonoObject* sender,
MonoObject* args)
{
...
}
To hook the handler you have create a delegate for
EventHandlerICall using Delegate.CreateDelegate and
add it to the event with method obtained from
mono_event_get_add_method.
Robert
More information about the Mono-list
mailing list