J
Jack
Hi,
I am writing a COM server with ATL and VC++.NET. I wonder if there is a way
to reuse COM method implementations without delegation, something like this:
__interface IFoo : IDispatch
{
[id(1)] HRESULT MyMethod();
// other method declarations...
}
class CFooBase : public IFoo
{
STDMETHOD( MyMethod )()
{
// General default implementation
return S_OK;
}
// Default implementation for other IFoo methods, too
};
[coclass...]
class ATL_NO_VTABLE COneFoo : public CFooBase
{
// Here there are specialized implementation for only those IFoo methods
that
// this particular COM object wants to override. Other ones would use the
derived
// implementation in CFooBase without doing anything in this class.
};
The above code would not compile in VC++.NET, although a similar construct
worked in VC++ 6.0 (with all those templatized base classes and stuff). I
know I can write a non-STDMETHOD implementations in CFooBase and then
delegate to them in COneFoo (and its sibling classes) but that requires
modification in all those coclasses every time I make a change in IFoo.
Because COneFoo and its sibling classes will have the same implementation
for many of the methods declared in IFoo it feels stupid to rewrite the
implementation (or even a delegate function) in every one of them.
So, is there a way to do it without delegation? Thank you for your help!
Regards,
Jack
I am writing a COM server with ATL and VC++.NET. I wonder if there is a way
to reuse COM method implementations without delegation, something like this:
__interface IFoo : IDispatch
{
[id(1)] HRESULT MyMethod();
// other method declarations...
}
class CFooBase : public IFoo
{
STDMETHOD( MyMethod )()
{
// General default implementation
return S_OK;
}
// Default implementation for other IFoo methods, too
};
[coclass...]
class ATL_NO_VTABLE COneFoo : public CFooBase
{
// Here there are specialized implementation for only those IFoo methods
that
// this particular COM object wants to override. Other ones would use the
derived
// implementation in CFooBase without doing anything in this class.
};
The above code would not compile in VC++.NET, although a similar construct
worked in VC++ 6.0 (with all those templatized base classes and stuff). I
know I can write a non-STDMETHOD implementations in CFooBase and then
delegate to them in COneFoo (and its sibling classes) but that requires
modification in all those coclasses every time I make a change in IFoo.
Because COneFoo and its sibling classes will have the same implementation
for many of the methods declared in IFoo it feels stupid to rewrite the
implementation (or even a delegate function) in every one of them.
So, is there a way to do it without delegation? Thank you for your help!
Regards,
Jack