|
-
Dec 9th, 2004, 02:35 AM
#1
Thread Starter
Randalf the Red
VB.Net, COM Interop and User-defined events
Hi all,
We need to develop a COM component in VB.Net for use in COM client applications. We developed a sample COM Interop component in VB.Net and tried to use it in VB. The sample component has a Message property, a DisplayText method and an OnMessageDisplay event. Things work smoothly for the property assignment and method invocation. However when it comes to handling the OnMessageDisplay event, I can't seem to find how I can handle it.
Here's the code in VB6:
Code:
Option Explicit
Dim myObj As TestInterop.TestInterop
Dim myEvent As OnMessageDisplayEventHandler
Private Sub Form_Click()
myObj.Message = "Hello Anand"
myObj.DisplayText
End Sub
Private Sub Form_Load()
Set myObj = New TestInterop.TestInterop
myevent.
myObj.add_OnMessageDisplay myEvent
End Sub
Private Sub OnMessageDisplay()
MsgBox ("Event handler invoked")
End Sub
For a true COM component I could simply have used WithEvents myObj and the job would be done. However here I am stuck as to how I can specify the OnMessageDisplay() procedure as the event handler for the OnMessageDisplay event. Can someone help me out with this?
.
-
Dec 9th, 2004, 05:22 AM
#2
Re: VB.Net, COM Interop and User-defined events
Hi
I would use delegates.
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Dec 9th, 2004, 05:36 AM
#3
Thread Starter
Randalf the Red
Well ...
Thanks for the reply, Asgorath?
I found this link that helps with the problem I faced:
http://www.devcity.net/net/article.aspx?alias=20020328
After creating the interface, the event sink now works and I can use the object with WithEvents declaration like normal COM objects 
.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|