This article was previously published under Q141277
Note Microsoft Visual C++ NET (2002) supported both the managed code
model that is provided by the .NET Framework and the unmanaged native Windows
code model. The information in this article applies to unmanaged Visual C++
code only.
Note Microsoft Visual C++ 2005 supported both the managed code
model that is provided by the .NET Framework and the unmanaged native Windows
code model.
In an MFC application, you can override existing interfaces
in a class as well as provide additional interfaces. Overriding an interface in
this case is synonymous with replacing an interface. The example in this
article illustrates how to override an interface in a class while preserving
the original interface implementation so that it can be delegated to by the new
interface implementation.
This article does not deal with overriding
the IDispatch implementation, as this is a special case.
For more information about how to override IDispatch in MFC, click the following article number to view the article in the Microsoft Knowledge Base:
This adds a nested class XMyOleObject to your control class. Note that
these macros declare interface methods including the IUnknown interface
methods, so you must implement the IUnknown methods as well.
Add the IOleObject interface to the interface map for the
control by adding an INTERFACE_PART macro to the implementation file for the
control:
The rest of the methods follow the same pattern where
CIOleOverCtrl is the name of the control, XMyOleObject is the name of the
nested class that supports IOleObject, and m_xMyOleObject is calculated by
removing the I from the interface being supported and adding m_x.
Note that these methods simply pass the call on to the original IOleObject
implementation. However, this is not a requirement; you could add functionality
and delegate to the original implementation or not delegate at all.