how to use a com component in .net that implements a .net interfac

M

mprmax

I have an interface defined in .NET that is exposed to COM. I have a VB6
component that implements this interface. If I try to use this VB6 component
in .NET and the InterfaceType attribute on the .NET Interface is set to
anything other than ComInterfaceType.InterfacesIsIDispatch then the code
fails.

When set to ComInterfaceType.ComInterfaceType.InterfaceIsDual the properties
just don't work but no errors occur. When
ComInterfaceType.InterfaceIsIUnknown memory access violation errors occur.
 
M

Michel Posseth [MCP]

maybe you could explain a bit more cause how i understand it now it sounds a
bit silly to me

You have a interface ? ( A : Iinterface , eg a skeleton for a type , B:
or do you mean a full blown object wich has a API that you call interface )

if it is option A well why would you need VB6 at all ?

The VB6 assembly should be COM / ACTIVEX ( i prefer Activex executables as
they are out of proces ) the methods . properties that you want to expose
should be in a COM creatable class


michel
 
M

mprmax

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top