d***@gmail.com
2008-06-14 22:50:54 UTC
In a code review, I encountered a method that is supposed to create
and return a COM interface. In the implementation of this method, the
author used the 'new' operator on the C++ class that implements the
COM interface (this C++ class is in the same cpp file and DLL). Then,
the author called AddRef, and returned the class instance from this
method.
This obviously raised red flags, but what are the best arguments for
calling CoCreateInstance (vs. new)?
In this particular case, there was no threading/apartment concerns
either, but I am generally interested in understanding what are the
primary gotchas code like this would encounter.
Any comments/experiences?
and return a COM interface. In the implementation of this method, the
author used the 'new' operator on the C++ class that implements the
COM interface (this C++ class is in the same cpp file and DLL). Then,
the author called AddRef, and returned the class instance from this
method.
This obviously raised red flags, but what are the best arguments for
calling CoCreateInstance (vs. new)?
In this particular case, there was no threading/apartment concerns
either, but I am generally interested in understanding what are the
primary gotchas code like this would encounter.
Any comments/experiences?