Inheritance and COM

  • Thread starter Thread starter Alan Sloan
  • Start date Start date
A

Alan Sloan

I have a Class Library that I am writing that is COM visible to maintain a
VB6 app. In this Class Library I have the following classes.

Public Class SomeBaseObject

Public Function DoSomething() as Boolean
.....
End Function
....
End Class

<ComClass(Item.ClassId, Item.InterfaceId, Item.EventsId)> _
Public Class MyDerivedClass
Inherits SomeBaseObject

' These GUIDs provide the COM identity for this class
Public Const ClassId As String = "95af8113-4a12-42e4-b6f9-8beb9bdf7591"
Public Const InterfaceId As String =
"1f7e7d99-d1c0-4732-8d2d-20c258d4883f"
Public Const EventsId As String = "de109a8b-ad82-4ed7-8442-087d2ba569c3"

....
End Class

When I use MyDerivedClass in a .net assy, I can instantiate the
MyDerivedClass object and the method DoSomething is visible and available as
you would expect.

When I use MyDerivedClass in my VB6 app, I can instantiate the
MyDerivedClass "object" but I cannot see the method DoSomething(or anything
else) from the base class. All I can see or access are the properties and
methods of the MyDerivedClass object.

What am I missing? Any help would be greatly appreciated!
Alan
 
Am 10.06.2010 22:03, schrieb Alan Sloan:
I have a Class Library that I am writing that is COM visible to maintain a
VB6 app. In this Class Library I have the following classes.

Public Class SomeBaseObject

Public Function DoSomething() as Boolean
.....
End Function
....
End Class

<ComClass(Item.ClassId, Item.InterfaceId, Item.EventsId)> _
Public Class MyDerivedClass
Inherits SomeBaseObject

' These GUIDs provide the COM identity for this class
Public Const ClassId As String = "95af8113-4a12-42e4-b6f9-8beb9bdf7591"
Public Const InterfaceId As String =
"1f7e7d99-d1c0-4732-8d2d-20c258d4883f"
Public Const EventsId As String = "de109a8b-ad82-4ed7-8442-087d2ba569c3"

....
End Class

When I use MyDerivedClass in a .net assy, I can instantiate the
MyDerivedClass object and the method DoSomething is visible and available as
you would expect.

When I use MyDerivedClass in my VB6 app, I can instantiate the
MyDerivedClass "object" but I cannot see the method DoSomething(or anything
else) from the base class. All I can see or access are the properties and
methods of the MyDerivedClass object.

What am I missing? Any help would be greatly appreciated!
Alan


The ComClass attribute is the "quick" way to have interfaces created, but as you
see, it has it's drawbacks.

Inm VB6, you can still assign a MyDerivedClass object to a variable of type
SomeBaseObject because the object implements the base class interface:

dim var as SomeBaseObject

set var = new MyDerivedClass
var.DoSomething 'Works



I prefer to have no interface created automatically. Instead, i implement them
explicitly. Have a look at the ClassInterface attribute. Instead of creating
example code by myself, this seems to be an explaining discussion about it:
http://social.msdn.microsoft.com/fo.../thread/7313191a-10db-4a16-9cdd-de9fb80b378a/
 
Back
Top