Re: COM virtual functions?
Scott McPhillips [MVP] <org-dot-mvps-at-scottmcp> wrote:
My DLL inherits from _IDTExtensibility2 to receive calls from Word,
so I can't change that interface. Does COM provide any mechanism
similar to C++ inheritance and virtual functions? This would let
another DLL inherit from my class and override calls from Word, and
pass them on to my DLL when desired?
COM only deals with interfaces. It does not know, nor care, about how
you implement an interface. COM provides interface inheritance (which is
basically just adding new methods to existing interface and giving the
result a new name), but is neutral to implementation inheritance (that
is, neither requires nor prohibits it).
Yes, in C++, you can provide partial implementation of an interface in
one class, then have another class derive from it and complete the
implementation. You do this in ATL all the time, when you derive from
IDispatchImpl or IPersistStreamInitImpl and so on.
On the other hand, and quite unrelated to COM, it is often unwise to
export C++ classes from a DLL. Since there is no binary standard on how
a C++ class is represented in memory, exporting such a class is unsafe
unless both exporting and importing modules are built with the same
version of the same compiler with the same compiler settings. At which
point it's not clear why make it a separate DLL at all, and not just
build all the source code into a single module. This is precisely the
problem that COM, with its reliance on binary compatible interfaces, is
designed to solve.
Why not do the following. Have your DLL provide an object A implementing
_IDTExtensibility2. Have the other DLL provide an object B implementing
the same interface. B is registered with Word, and also creates an
instance of A. B's methods may forward some or all calls to
corresponding A's methods.
With best wishes,
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925