Re: How to have an interface as a member variable
If you need to expose a nested object (and it seems like it
based on your posts, though I'm still not entirely clear...)
you should have a look at this FAQ article:
http://vcfaq.mvps.org/com/12.htm
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
"Kim Gr?sman" <kim@mvps.org> wrote in message
news:ba04e56518df8c8fee81f2a1e9a@news.microsoft.com...
Hi prose,
I'm sorry, that was a cut and paste error. The corrected code follows.
Ah, I see...
BTW, the error I got when I tried to directly include CMyData as a
member variable was the compiler complaining about pure virtual
functions QueryInterface, AddRef, and Release. Do I need to redefine
these in CMyData or is that taken care of for me? If I do need to
redefine these, what do they need to contain?
No, you shouldn't define them. ATL is built according to a "sandwich
model", which means that you derive from ATL (CComObjectRootEx), write
your code, and then ATL derives from your class to form a fully concrete
class.
The ATL template classes that derive from yours are called
CComObject-something.
So if you need access to the C++ class CMyData, you should keep a member
of CComObject<CMyData>* in your CMyClass class -- the template
instantiation forms a fully concrete implementation of IUnknown and your
interfaces.
As it derives from your class, you have "full C++ access" to methods and
member variables on CMyData, whereas IMyData only exposes COM-friendly
stuff.
See the archives for details on CComObject, how to manage their lifetime,
etc.
Cheers,
- Kim