user540983
user540983

Reputation:

shared_ptr - ccomptr swap

I got a simple question here

Let's suppose we have a codebase that employs usage of shared_ptr/enable_shared_from_this.

And we have been asked to convert -a portion of- the codebase into a COM server where we are supposed to use CComPtr instead, while it is not a mandatory requirement...

now here is the question; Is there any functionality within the atl/com+ that mimics enable_shared_from_this?

Upvotes: 1

Views: 469

Answers (2)

Mark Ransom
Mark Ransom

Reputation: 308130

There are lots of rules for COM objects, it's not as easy as declaring a smart pointer. I'd suggest studying up on the subject, it's not something that can be condensed into a short answer.

Upvotes: 0

Jon
Jon

Reputation: 3065

There is no need for enable_shared_from_this when using CComPtr because CComPtr does not maintain a reference count. Instead, the object it points to maintains the reference count. All CComPtr does is call member functions on the object that increment or decrement the reference count. There is no problem with doing the following:

void Func(IUnknown* someObj)
{
    CComPtr ptrA = someObj;
    CComPtr ptrB = someObj;
}

Upvotes: 1

Related Questions