Raise Event of Class implementing Interface VB.Net

  • Thread starter Thread starter Sai Prakash
  • Start date Start date
S

Sai Prakash

Hi,

I am creating a vb.net interop dll which implements an interface to
access the functions and properties of the class. Is there any way I
can raise the events of the class too ? The events were working fine
before adding the interface. I read through a number of articles, but
could not implement them in my code. The structure of my dll is as
follows:
.................................................................................................................
Imports System.Runtime.InteropServices

<ComVisible(True)> _
<Guid(InteropUserControl.InterfaceId)> _
Public Interface IInteropUserControl
Function OleConnected() As String
Property Layers() As Integer
End Interface

<ComVisible(True)> _
<Guid(InteropUserControl.ClassId)> _
<ComDefaultInterface(GetType(IInteropUserControl))> _
Public Class InteropUserControl
Implements IInteropUserControl

Dim iLayers as Integer

Public Property Layers() As Integer Implements
IInteropUserControl.Layers
Get
Return iLayers
End Get
Set(ByVal value As Integer)
iLayers = value
End Set
End Property

Public Function OleConnected() As String Implements
IInteropUserControl.OleConnected
Return "Connected to VB.Net"
End Function


End Class
......................................................................................................

Thanks for any help.

Priya
 
Can you please describe your problem better? What do you mean when you say
events work before you added the interface? What kind of error are you
getting?
 
Hi,

I am not getting errors. It is just that the events of the dll are no
longer visible in the application which implements the class. I tried
creating another interface for events. Now my dll structure is :

Imports System.Runtime.InteropServices

<ComVisible(True)> _
<Guid(InteropUserControl.InterfaceId)> _
Public Interface IInteropUserControl
Function OleConnected() As String
Property Layers() As Integer
End Interface

<ComVisible(True)> _
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface IEvents
Event LayerClick()
End Interface

<ComVisible(True)> _
<Guid(InteropUserControl.ClassId) >_
<ComDefaultInterface(GetType(IInteropUserControl)),
ComSourceInterfaces(GetType(IEvents))> _

Public Class InteropUserControl
Implements IInteropUserControl

Dim iLayers as Integer

Public Event LayerClick() Implements IEvents.LayerClick

Private Sub InteropUserControl_DoubleClick(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Me.DoubleClick
RaiseEvent LayerClick()
End Sub

Public Property Layers() As Integer Implements
IInteropUserControl.Layers
Get
Return iLayers
End Get
Set(ByVal value As Integer)
iLayers = value
End Set
End Property

Public Function OleConnected() As String Implements
IInteropUserControl.OleConnected
Return "Connected to VB.Net"
End Function

End Class

....................................................................................................

Now I can see the event "LayerClick" in my application, but it does
not fire.
Anything I am missing out. I am very new to COM.

Thanks
 
Back
Top