Hi Mike,
I have an interface defined in .NET called IContact. I have applied the
necessary COM Interop attributes so that the Interface is exposed to COM i.e.
<Guid("8C125761-0253-4152-986B-F27A155F72C6"), ComVisible(True),
InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IContact
<DispId(1)> _
Property Id() As Integer
<DispId(2)> _
Property Address1() As String
<DispId(3)> _
Property Address2() As String
End Interface
I have a VB6 component "B2GBOContact.BOContact" that implements this
interface (IContact)
I have some more VB.NET code that uses the VB6 component i.e.
Dim boContact as New B2GBOContact.BOContact
Dim oIContact as IContact = boContact
oIContact.Address1 = "Address Line 1" '-- Only works when InterfaceType
'--(ComInterfaceType.InterfaceIsIDispatch)
It may seem strange to have the a VB6 component and the Interface in .NET
but this is a requirement.
I have found that i get a memory access violation error when
ComInterfaceType.InterfaceIsDual and the code just fails to work (but no
error) when ComInterfaceTypeIsIUnknown (Maybe the other way around - I Forget
now)
Furthermore If I create a concrete class in .NET that implements the
interface i.e.
<Guid("17C80A81-69F5-4dad-9E5C-C4AD47938164"), _
ComVisible(True), _
ClassInterface(ClassInterfaceType.None), _
ProgId("DataValidation")> _
Public Class Contact
Implements IContact
....
and get the VB6 component to implement this concrete class then eveything
works Ok regardless of the setting of ComInterfaceType in the .NET Interface.
In fact as soon as I define the Contact class in .NET I am no longer able to
see the IContact interface in the exported type library and can only
implement the Contact class.
Not sure whats going on here and would love to know why I am getting the
errors when using the IContact interface from .NET. I should note that no
errors ever occur when other VB6 code uses the VB6 component and the IContact
interface - the error only occurs from .NET.
Hope this explains everything