Hidden interface

  • Thread starter Thread starter Fox
  • Start date Start date
F

Fox

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
 
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 CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CA, &CLSID_A>,
public IDispatchImpl<IA, &IID_IA, &LIBID_PINT23Lib>
{
...

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.
--------------------
 
Back
Top