Hidden interface

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fox

    Hidden interface

    Hi all,

    I would like to ask you a question regarding inheritence in C#.

    I have a class which inherits from COM object, but then I want to pass
    this class to the function expecting interface which COM object is
    inherited from, I can't do it.

    See sample:

    C++ ATL project with COM interface A and COM object AInst
    interface A
    {
    // some methods
    }

    class AInst : public A
    {
    // some methods
    }

    In C# I would like to do:
    class AInstCSharp : public AInst
    {
    }

    class B
    {
    public static void Do( A a )
    {
    //do something
    }
    }

    Now somewhere in C# code:
    AInstCSharp a = new AInstCSharp();

    //next line will not compile due to an error CS1502
    B.Do( a );

    It seems that original interface A can't be used and also in object
    browser I can't see that class AInstCSharp is inherited from A.
    Do you have any idea how I can use it?

    Fox
  • Gary Chang

    #2
    RE: Hidden interface

    Hi Fox,

    For a default ATL COM object which inherits the interface A, it's
    definition would be like:
    class ATL_NO_VTABLE CA :
    public CComObjectRootE x<CComSingleThr eadModel>,
    public CComCoClass<CA, &CLSID_A>,
    public IDispatchImpl<I A, &IID_IA, &LIBID_PINT23Li b>
    {
    ...

    and when I tested the following code in a C# program, it is compiled OK:
    public class AInstCSharp : AClass //the COM object CA
    {
    }

    class B
    {
    public static void Do( A a ){}
    }
    ...
    AInstCSharp a = new AInstCSharp();
    B b = new B();
    B.Do(a);

    ...

    I think the class AInst in your code snippet may be not a valid COM object,
    so you cannot see the interface A in object browser.


    Thanks!

    Best regards,

    Gary Chang
    Microsoft Online Partner Support

    Get Secure! - www.microsoft.com/security
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------

    Comment

    Working...