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 / .NET Framework / Interop / September 2005

Tip: Looking for answers? Try searching our database.

COM calling .NET methods, and inherited interfaces.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gemma M - 16 Sep 2005 10:38 GMT
Hi,

I have a COM component which calls methods on a .NET object.  However, some
methods originate in an inherited interface.  COM cannot "see" the inherited
methods.

In the code fragment below, if a COM component creates an instance of Child
class, it cannot "see" the property ParentKey.

Am I missing something?  Is there a way around this?  Do I have to duplicate
methods and properties in the child class/interface that are inherited from
the parent, for COM to "see" them?

Regards
Gem

---- .NET Code fragment ----
public interface IParent {
   string ParentKey { get; set; }
}

public class Parent : IParent {
   private string key = "";

   public string ParentKey {
       get {
           return this.key;
       }
       set {
           this.key = value;
       }
   }   // public string ParentKey...
}

public interface IChild : IParent {
   string ChildKey { get; set; }
}

public class Child : Parent {
   private string childKey = "";

   public string ChildKey {
       get {
           return this.childKey;
       }
       set {
           this.childKey = value;
       }
   }   // public string ChildKey...
}

---- COM code fragment ----

Dim childObject as ChildParentNet.Child
Dim child as ChildParentNet.IChild

Set childObject = new ChildParentNet.Child
set child = childObject

Both child.ParentKey and childObject.ParentKey throw a 438, "Object doesn't
support this property or method" exception.

Gem
Robert Jordan - 16 Sep 2005 11:52 GMT
Hi Gem,

> public interface IChild : IParent {
>     string ChildKey { get; set; }
> }
>
> public class Child : Parent {

BTW, you forgot to inherit from IChild.

I never programmed with VB6, thus I don't know whether it
uses late-binding or early-binding.

Your code is ok for late-binding but it won't work
for early-binding clients. For those clients you
must apply

[ClassInterface(ClassInterfaceType.None)]

to your class declarations.

On the other way, setting ClassInterfaceType.None doesn't work
with late-binding clients, so if you want to support both
kind of bindings, you have to use ClassInterfaceType.AutoDual.

See

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conIntroducingClassInterface.asp


Be aware about the implications of using ClassInterfaceType.AutoDual:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemruntimeinteropservicesclassinterfacetypeclasstopic.asp


Rob
Gemma M - 16 Sep 2005 16:23 GMT
Thanks for the info.

Gem
> Hi Gem,
>
[quoted text clipped - 30 lines]
>
> Rob

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.