COM Object 如何实现 Clone

zhp80 2003-05-13 01:38:23
如题
...全文
41 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhp80 2003-05-23
  • 打赏
  • 举报
回复
谢谢你zzyx(菜农),我已经实现了,和你的方法有一些差别,如想交流我可以mail给你
另外,用你的方法,clone出副本后如何让副本的数据成员与母本的一样?通过属性的读写吗?那要有只读属性呢?
在有你用ATL做过集合吗?
zzyx 2003-05-22
  • 打赏
  • 举报
回复
刚才做了个东西,看看是不是你想要的(没有错误和异常处理)

服务器端:
STDMETHODIMP CComC::Clone(IDispatch **ppDisp)
{
// TODO: Add your implementation code here
CComPtr<IComC> p;
HRESULT hr=p.CoCreateInstance(L"MyCOM.ComC");
if(FAILED(hr))
{
return hr;
}
*ppDisp=(IDispatch*) p.Detach ();

return S_OK;
}

客户端测试:
void test()
{
IComCPtr p=NULL;
IComCPtr p2=NULL;
p.CreateInstance (L"MyCom.ComC");
... //可以使用p做一些工作
p2=p->Clone();//可龙了一个p2
p.Release (); //关闭了p
... //还使用p2仍然可以做一些工作
p2.Release ();//关闭p2
}

zzyx 2003-05-22
  • 打赏
  • 举报
回复
IStream::Clone
This method creates a new stream object with its own seek pointer that references the same bytes as the original stream.

IXMLDOMNode::cloneNode
The cloned node has the same property values as this nodefor the following properties: nodeName property, nodeValue property, nodeType property, parentNode property, ownerDocument property, and, if it is an element, attributes property. The value of the clone's childNodes property depends on the setting of the deep flag parameter.
...

你到底要可龙成什么呀
zhp80 2003-05-19
  • 打赏
  • 举报
回复
没人会吗?
Rodriguez 2003-05-14
  • 打赏
  • 举报
回复
将一个内存块复制另一个内存块不知道可不可以
zhp80 2003-05-14
  • 打赏
  • 举报
回复
clone = 克隆
Sample: ADODB.Recordset.Clone() or MSXML.IXMLDomNode.Clone() ...
zzyx 2003-05-13
  • 打赏
  • 举报
回复
什么叫clone啊
zhp80 2003-05-13
  • 打赏
  • 举报
回复
是否与此有关?
Aggregation
There are times when an object's implementor would like to take advantage of the services offered by another, pre-built object. Furthermore, it would like this second object to appear as a natural part of the first. COM achieves both of these goals through containment and aggregation.

Aggregation means that the containing (outer) object creates the contained (inner) object as part of its creation process and the interfaces of the inner object are exposed by the outer. An object allows itself to be aggregatable or not. If it is, then it must follow certain rules for aggregation to work properly.

Primarily, all IUnknown method calls on the contained object must delegate to the containing object.

怎么实现?

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧