Hi all, below is most of my code for my COM InterOp object (For those =
following previous posts - I'm not using Inheritance any longer).
My class Logging is implementing ILogging and exposing LogToFile() and =
LogToScreen(). In the VB6 project the properties are showing up under =
the ILogging interface which is public. Is this the best way to expose =
my "Non-Event" methods (subs, functions, properties) to the COM world =
(VB6)? Are there other options to expose my public methods and =
properties?
Note: The ILoggingEvents interface is used to handle the events of my =
Logging class (ComSourceInterfaces() attribute).=20
<Guid("26014480-5D35-49ed-B83C-1B862BF92517")> _
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface ILoggingEvents
<DispId(1)> _
Sub LogExitDisplayLoggingWindow()
<DispId(2)> _
Sub LogErrorOccurred(ByVal outEx As Exception)
End Interface
=20
<Guid("542FA6CF-F2C8-46d3-8601-EF370BBEF146")> _
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface ILogging
Property LogToFile() As Boolean
Property LogToScreen() As Boolean
End Interface
=20
#End Region
=20
<Guid("64439B0F-D1BF-43d7-BCD9-BA908BF2CCF6")> _
<ClassInterface(ClassInterfaceType.None)> _
<ProgId("CLA_Logging.Logging")> _
<ComSourceInterfaces(GetType(ILoggingEvents))> _
Public Class Logging
Implements IDisposable
Implements ILogging
=20
Public Delegate Sub LogExitDisplayLoggingWindowHandler()
Public Delegate Sub LogErrorOccurredHandler(ByVal outEx As =
Exception)
Public Event LogExitDisplayLoggingWindow As =
LogExitDisplayLoggingWindowHandler
Public Event LogErrorOccurred As LogErrorOccurredHandler
=20
Public Sub New()
Try
If m_formInstance Is Nothing Then
m_formInstance =3D New frmLogDisplay()
m_formInstance.ParentLogging =3D Me
End If
Catch ex As Exception
ProcessException(ex)
End Try
End Sub
=20
Public Property LogToFile() As Boolean Implements ILogging.LogToFile
Private Get
Try
Return m_LogToFile
Catch ex As Exception
ProcessException(ex)
End Try
End Get
Set(ByVal value As Boolean)
Try
m_LogToFile =3D value
Catch ex As Exception
ProcessException(ex)
End Try
End Set
End Property
=20
Public Property LogToScreen() As Boolean Implements =
ILogging.LogToScreen
Private Get
Try
Return m_LogToScreen
Catch ex As Exception
ProcessException(ex)
End Try
End Get
Set(ByVal value As Boolean)
Try
m_LogToScreen =3D value
Catch ex As Exception
ProcessException(ex)
End Try
End Set
End Property
=20
'*** Other code not shown.
End Class=20
Note: I'll have to change my event that is using the Exception object. =
I'll probably have to make additional changes as well.
Great Links:
(Part 1)
http://www.15seconds.com/issue/040721.htm (Part 2)...
http://www.15seconds.com/issue/060309.htm http://www.codeproject.com/dotnet/cominterop.asp ....(See Part 2)