[Mono-list] Mono Embedding: manage events
Robert Jordan
robertj at gmx.net
Mon Apr 7 15:08:49 EDT 2008
Ing. Francesco Carsana wrote:
> Thank you for the example Robert!
>
> > // call AttachEvent(session);
> > args [0] = session;
> > mono_runtime_invoke (attach_event_method, NULL,
> > args, &exception);
>
> In this piece of code, what's the type of session?
> Is it a MonoObject* ?
> I've tried this:
>
> MonoObject* session;
> MonoAssembly* assembly;
> MonoClass* klass;
> MonoObject* session;
> MonoDomain* domain;
> MonoImageOpenStatus status;
>
> domain = mono_jit_init("session.dll");
> assembly = mono_assembly_open("session.dll", &status);
> klass = mono_class_from_name(mono_assembly_get_image(assembly),
> "namespace", "Session");
> session = mono_object_new(domain, klass);
> mono_runtime_object_init(session);
>
> mono_add_internal_call("ConnectionEventWrapper::UnmanagedHandler",
> &icall_ConnectionEventWrapper_UnmanagedHandler);
>
> gpointer args[1];
> args[0] = session;
> mono_runtime_invoke(attach_event_method, NULL,
> args, &exception);
>
> Is it right?
> In this way I can't catch the event in C++:
> it compiles but it doesn't work.
> The Session class in session.dll raise the event but
> the function icall_ConnectionEventWrapper_UnmanagedHandler is
> never called...
> Is there something wrong?
Since you're creating the Session object inside the code above,
I wonder how the event is fired at all.
Your code is equivalent to
Session s = new Session ();
s.SomeEvent += someHandler;
This code does not fire any events, unless there is some external
stimulus in your real code.
Robert
More information about the Mono-list
mailing list