Hello,
I am creating an out-of-process COM server to host a number of 32-bit DLLs so that they can be accessed by a 64-bit process through 'wrapper interfaces'. Each of these wrapper interfaces implements the IDispatch interface as well as a number of 'wrapper methods' that access the 32-bit DLLs.
Because the implementations of the IUnknown and IDispatch methods are nearly identical in each wrapper interface, I thought I could save some time by implementing these methods in a base class and having each of the wrapper interfaces inherit these implementations.
The way I have structured my code, the base interface inherits IDispatch, and the base class inherits the base interface. The child interface inherits nothing, and the child class inherits the child interface and the base class.
According to Microsoft, "If you are using C++ multiple inheritance to implement multiple interfaces, the various interfaces can share one implementation of IUnknown."
It will be some time before I can really test this out. Has anyone tried something like this before? Is it possible for COM objects to inherit implementations of common interfaces?
Thanks in advance for your comments or suggestions.
My code looks something like this:
import "oaidl.idl";
import "ocidl.idl";
import "unknwn.idl";
[
object,
uuid(...),
dual,
oleautomation
]
interface IBase : IDispatch
{ }
[ uuid(...) ]
library BaseLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
interface IBase;
[ uuid(...) ]
coclass Base
{
[default] interface IBase;
}
}
************************
#include "Base_h.h"
class Base : public IBase
{
public:
Base();
~Base();
HRESULT STDMETHODCALLTYPE QueryInterface(...);
ULONG STDMETHODCALLTYPE AddRef();
ULONG STDMETHODCALLTYPE Release();
HRESULT STDMETHODCALLTYPE GetTypeInfoCount(...);
HRESULT STDMETHODCALLTYPE GetTypeInfo(...);
HRESULT STDMETHODCALLTYPE GetIDsOfNames(...);
HRESULT STDMETHODCALLTYPE Invoke(...);
protected:
long m_RefCount;
};
*********************
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(...),
dual,
oleautomation
]
interface IChild
{
[ uuid(...)]
library ChildLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
interface IChild;
[ uuid(...) ]
coclass Child
{
[default] interface IChild;
}
}
*******************
#include "Base.h"
#include "IChild_h.h"
class Child : public IChild, public Base
{
public:
Child();
~Child();
protected:
};