Results 1 to 3 of 3

Thread: VB.Net, COM Interop and User-defined events

  1. #1

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Question 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?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

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

  3. #3

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    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

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width