locked
Can base/derived classes be exported to COM? RRS feed

Answers

  • MVP Michael Taylor has articulated key points when using COM interop in C#:

    ·         COM only deals with interfaces.   Base/derived classes have no meaning or functionality in COM.   Inheritance is not applicable either.

    ·         In COM, interfaces can inherit from one another.   However, the .NET implementation that exports the .NET interface to COM does not support inheritance.   Therefore, you must replicate any interface members in a base interface to the derived interface.

    ·         Moving members between a base and derived class will have no impact on what is visible to COM.

    ·         Only the programmer can define what is exposed to COM.   The complier will not use reflection or anything else to determine what should be exposed.

    ·         All COM classes have a single, default interface.   This is the interface that is normally used for an object.   A COM class can expose other interfaces but the COM client must then query for the interface.   In .NET the first COM visible interface is used as the default interface for a COM class.  

    Related thread:
    http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/7313191a-10db-4a16-9cdd-de9fb80b378a/

     

    For more FAQ about Visual C# General, please see Visual C# General FAQ

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

    Tuesday, April 7, 2009 6:48 AM

All replies

  • MVP Michael Taylor has articulated key points when using COM interop in C#:

    ·         COM only deals with interfaces.   Base/derived classes have no meaning or functionality in COM.   Inheritance is not applicable either.

    ·         In COM, interfaces can inherit from one another.   However, the .NET implementation that exports the .NET interface to COM does not support inheritance.   Therefore, you must replicate any interface members in a base interface to the derived interface.

    ·         Moving members between a base and derived class will have no impact on what is visible to COM.

    ·         Only the programmer can define what is exposed to COM.   The complier will not use reflection or anything else to determine what should be exposed.

    ·         All COM classes have a single, default interface.   This is the interface that is normally used for an object.   A COM class can expose other interfaces but the COM client must then query for the interface.   In .NET the first COM visible interface is used as the default interface for a COM class.  

    Related thread:
    http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/7313191a-10db-4a16-9cdd-de9fb80b378a/

     

    For more FAQ about Visual C# General, please see Visual C# General FAQ

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

    Tuesday, April 7, 2009 6:48 AM
  • Introduction and Reference:

    COM Interop is a wonderful technology.   One aspect of the common language runtime (CLR) that makes it an extremely powerful platform is that it allows seamless interactions between managed applications and unmanaged COM components.   For a detailed introduction and code example, please refer to Introduction to COM Interop by Thottam R. Sriram.

    Here is a tutorial that shows how to use C# to interoperate with unmanaged COM objects:
    http://msdn.microsoft.com/en-us/library/aa645736.aspx

    Here is a tutorial that demonstrates how to communicate between unmanaged applications and managed COM components written in C#:
    http://msdn.microsoft.com/en-us/library/aa645738.aspx



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

    Tuesday, April 7, 2009 7:08 AM