Re: ATL-COM: return pointer to instance
From: Simon Trew (noneofyour_at_business.guv)
Date: 02/17/05
- Next message: Mark Ingram: "Howto inherit from a templated class?"
- Previous message: Bil Muh: "How to Update a Column of DataGrid FAST?"
- In reply to: Joe: "Re: ATL-COM: return pointer to instance"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Feb 2005 11:40:20 -0000
"Joe" <joerider@uboot.com> wrote in message
news:uumercDFFHA.628@TK2MSFTNGP15.phx.gbl...
>
> If I want to access to a function on CTree/ITree I can redirect it to
> tree_. The problem is, that I don't want to create an Instance of
> CItem/IItem for each Item-Instance. Otherwise I would rebuild the whole
> tree a second time.
>
> In my opinion CItem should hold a pointer to the original Item-Instance.
> So I can access all members directly.
Okay, that's what I was trying to say before. Your CItem is just a proxy for
the 'real' data and you expect it to have a shorter lifetime (i.e. it can be
created/deleted as required, without the 'real' data being created/deleted).
So yes, use a pointer or reference back to the original item. I'd call this
the 'proxy' pattern, though it may well be that there's another formal name
for it (on the whole I find the GoF's pattern names rather cryptic).
> If I want to access the root, I somewhere need to create an instance of
> a CItem and delete it somewhere. Then I want to read some Variables like
> the name and afterwards the object can be destroyed.
> For what reason should I call parent->AddRef() ?
> Does this delete the Object when I set the Object in VB to Nothing?
You should call AddRef any time you are handing a new reference to the
interface. In this case you are handing out parent to the VB client, so now
both your own code and the VB code refer to the interface, so you should
call AddRef before handing it out.
VB will call Release() when you set the Object variable to Nothing. Then,
the stock ATL code for Release() will end up deleting the object (with
"delete this") if the reference count has fallen to zero.
> How can I do that? Another Memberfunction?
You don't need to; the VB client will. All interfaces inherit from IUnknown
which defines AddRef() and Release(), and you will inherit your class from
an ATL class (CComObject) which defines stock implementations.
> Thanks, Joe
- Next message: Mark Ingram: "Howto inherit from a templated class?"
- Previous message: Bil Muh: "How to Update a Column of DataGrid FAST?"
- In reply to: Joe: "Re: ATL-COM: return pointer to instance"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|