Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mprmax - 28 Mar 2008 16:02 GMT
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.
Michel Posseth  [MCP] - 29 Mar 2008 13:03 GMT
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

>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
[quoted text clipped - 7 lines]
> just don't work but no errors occur. When
> ComInterfaceType.InterfaceIsIUnknown memory access violation errors occur.
mprmax - 31 Mar 2008 10:49 GMT
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

> maybe you could explain a bit more cause how i understand it now it sounds a
> bit silly to me
[quoted text clipped - 21 lines]
> > just don't work but no errors occur. When
> > ComInterfaceType.InterfaceIsIUnknown memory access violation errors occur.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.