[JDEV] JabberCOM in C#
Robert Temple
robert.temple at dig.com
Tue Feb 20 11:58:36 CST 2001
I haven't used JabberCOM and C# together but I just started using
C# with my own Jabber COM library and I got it to work.
It looks to me like you are using the wrong delegate and the wrong
function signature for the event. The "EventHandler" delegate is only
useful for events that fire with a signature of:
void foo(Object, EventArgs).
This is the typical function signature for most events inside of the
.NET library, but not all. Most COM events have their own signature.
I ran the JabberCOM.dll through the tlbimp.exe tool and then looked
at the results using the IL disassembler tool.
According to that tool, the method signature of the OnConnect event
is just void foo() so you should change your myOnConnectHandler to
look like this:
public void myOnConnectHandler(){
//handle this event here.
}
then, you need to wrap that using the appropriate delegate, again
the IL tool shows me what to use:
session.OnConnect +=
new IJabberSessionEvents_OnConnectEventHandler(this.myOnConnectHandler);
That should do it. Remember you need to reference the DLL that was
created using the tlbimp tool when you compile.
Good Luck,
-Robert
-----Original Message-----
From: Nathan Phelps [mailto:nphelps at solarc.com]
Sent: Friday, February 16, 2001 9:19 AM
To: 'jdev at jabber.org'
Subject: [JDEV] JabberCOM in C#
Does anyone have any experience using JabberCOM from Microsft's new C#
environment? I can't figure out how to do events. According to the C#
documentation you use a delegate. All the examples use the ever popular
button like so:
Button button = new Button();
button.Click += new EventHandler(this.myButtonClickHandler);
Then, in your class, you define a method called myButtonClickHandler which
handles the event like so:
public void myButtonClickHandler(object sender, EventArgs e){
//handle this event here.
}
This does indeed work for buttons and other events I've tested. However, I
can't seem to get the events in JabberCOM to work.
JabberSession session = new JabberSession();
session.OnConnect += new EventHandler(this.myOnConnectHandler);
public void myOnConnectHandler(object sender, EventArgs e){
//handle this event here.
}
It throws the following exception:
U:\Personal\Development\Projects\CSharp\Jabber\Class1.cs(14): Cannot
implicitly convert type 'System.EventHandler' to
'JabberCOM.IJabberSessionEvents_OnConnectEventHandler'
I am further mystified by the fact that the C# IDE shows all these extra
methods that I don't see from Visual Basic. For each event it includes an
add[EventNameHere]Handler and a remove[EventNameHere]Handler. Each takes
that particular type of event as its argument. I tried using these and
passing in an IJabberSessionEvents_OnConnectEventHandler, but as you might
imagine, that didn't work either.
Any ideas?
Thanks,
Nathan
_______________________________________________
jdev mailing list
jdev at jabber.org
http://mailman.jabber.org/listinfo/jdev
More information about the JDev
mailing list