COM implementation reuse without delegation

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
 
A

Alexander Nickolov

You probably want to ditch attributed ATL first. Then it's just
like VC6. Considering the bugs in the code generated by the
ATL attribute provider, this is a good idea on multiple levels...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: (e-mail address removed)
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top