-1

I have a COMVisible class MyAPI that my clients are going to use as the root object for all API access.

I have my APIs in another assembly OtherAPI that has Document and Window API classes (not COM visible).

I want to expose Document and Window classes via MyAPI class to a late binding client such as JavaScript.

[COMVisible(true)]
class MyAPI
{
    public OtherAPI::Document NewDocument()
    {
        return new OtherAPI::Document();
    }
}

// Something like this should work in the client code
(new MyAPI()).NewDocument().GetName();

The problem is that it does not see GetName because that is not COM visible I think.

I can wrap each and every function from Document and Window class in this class but I am looking for an elegant solution. I want my clients app to be able to use both Document and Window class functions via MyAPI object.

TheGeneral
  • 79,002
  • 9
  • 103
  • 141
A9S6
  • 6,575
  • 10
  • 50
  • 82

1 Answers1

0

You need to read the documentation...

Important parts highlighted for you viewing pleasure :)

ComVisibleAttribute Class

Setting the attribute to false on a specific type hides that type and its members. However, you cannot make members of a type visible if the type is invisible. Setting the attribute to false on a type prevents that type from being exported to a type library; classes are not registered; interfaces are never responsive to unmanaged QueryInterface calls.

However!

Unless you explicitly set a class and its members to false, inherited classes can expose to COM base class members that are invisible in the original class. For example, if you set ClassA to false and do not apply the attribute to its members, the class and its members are invisible to COM. However, if you derive ClassB from ClassA and export ClassB to COM, ClassA members become visible base class members of ClassB.

So it reads very clearly.

If you have marked the parent class members to false you cant expose them, however if its only the parent class that as been marked false (and the member aren't explicitly marked false), you can expose them.

Otherwise, you will have to re-implement them all again... Sorry, no free lunch here today

TheGeneral
  • 79,002
  • 9
  • 103
  • 141