如题

解决方案 »

  1.   

    是否与此有关?
    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.怎么实现?
      

  2.   

    clone = 克隆
    Sample: ADODB.Recordset.Clone() or MSXML.IXMLDomNode.Clone() ...
      

  3.   

    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.
    ...你到底要可龙成什么呀
      

  4.   

    刚才做了个东西,看看是不是你想要的(没有错误和异常处理)服务器端:
    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
    }
      

  5.   

    谢谢你zzyx(菜农),我已经实现了,和你的方法有一些差别,如想交流我可以mail给你
    另外,用你的方法,clone出副本后如何让副本的数据成员与母本的一样?通过属性的读写吗?那要有只读属性呢?
    在有你用ATL做过集合吗?