Re: ATL-COM: return pointer to instance
From: Joe (joerider_at_uboot.com)
Date: 02/16/05
- Next message: Carl Daniel [VC++ MVP]: "Re: Maximum memory available in XP"
- Previous message: Maksim P.: "Re: CProperty*** error"
- In reply to: Simon Trew: "Re: ATL-COM: return pointer to instance"
- Next in thread: Simon Trew: "Re: ATL-COM: return pointer to instance"
- Reply: Simon Trew: "Re: ATL-COM: return pointer to instance"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 16 Feb 2005 15:52:30 +0100
Simon Trew schrieb:
>>I think, I should use pointers in CItem that points at an item-instance.
> Not sure what you mean here.
tree and item define a full tree. The ATL-interface should only provide
a way to access data, that was created internally with tree and item.
The items have only read-only values that should be accessable by using ATL.
Perhaps I should tell more about the project. I've written a
client-server-application. Communication is done with xml (therefore i
need this tree. It reads files, text, etc to the tree-structure.) The
server-app uses the "Tree" and "Item" class. But I also need this tree
for the client that was written in VB. The client should make an
instance of ITree. With access-functions within ITree, IItems should be
returned. You see that I can reuse the tree in CTree/ITree
private:
Tree *tree_;
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.
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.
interface ITree : IDispatch
{
[id(1), helpstring("Method getRoot")] HRESULT getRoot([out,retval]
IItem* *res);
};
interface IXmlItem : IDispatch
{
[propget, id(1), helpstring("Eigenschaft Value")] HRESULT Value([out,
retval] BSTR *pVal);
[propget, id(2), helpstring("Eigenschaft Name")] HRESULT Name([out,
retval] BSTR *pVal);
};
CTree:
public:
STDMETHOD(getRoot)(IItem* *res);
private:
Tree *tree_;
CTree::CTree()
{
tree_ = new Tree("<test value=\"9\"/>");
}
STDMETHODIMP CTree::getRoot(IItem **res)
{
Item *it = tree_->getRoot();
//tree_ will not be destroyed until CTree is destroyed
CItem *ci = new CItem(it);
*res=ci;
return S_OK;
}
private:
Item *item_;
CItem::CItem()
{
item_ = NULL;
}
CItem::CItem(Item *item)
{
item_ = item;
}
CItem::~CItem()
{
if (item_ != NULL)
{
delete item_;
}
}
For what reason should I call parent->AddRef() ?
Does this delete the Object when I set the Object in VB to Nothing?
Dim Tree as new ITree
Dim Item as IItem
Tree.init(somestring)
set Item=Tree.getRoot()
debug.print Item.Value
Set Item=Nothing
After this there are no more references on the object
> Then, the client should call Itest->Release() (inherited
> from IUnknown) when it is done with it.
How can I do that? Another Memberfunction?
Thanks, Joe
- Next message: Carl Daniel [VC++ MVP]: "Re: Maximum memory available in XP"
- Previous message: Maksim P.: "Re: CProperty*** error"
- In reply to: Simon Trew: "Re: ATL-COM: return pointer to instance"
- Next in thread: Simon Trew: "Re: ATL-COM: return pointer to instance"
- Reply: Simon Trew: "Re: ATL-COM: return pointer to instance"
- Messages sorted by: [ date ] [ thread ]