Categories
Code Snippets

CComPtr – Return Value

Reminder – don’t forget to Detach() !!

IBody2 *SomeClass::getBody(int index)
{
  CComPtr<IBody2> target;
  target = CreateBody(index);
  return target.Detach();
}

Obvious perhaps, but the CComPtr will do a release as the function completes so if you’re returning the object remember to Detach it