Cannot use RAII wrapper types for COM objects. In particular, CComPtr<> , CComBSTR and CComVARIANT<> not used. These objects help prevent leaks by eliminating the responsibility for releasing the primary resource from the developer. The wrapper object enforces the destructor resources in it.
Another cause of leaks or random errors that I saw is the result of an implicit conversion from CComPtr<T> to T* . This is useful for passing wrapped objects as arguments. But this can cause problems because it allows an implicit conversion between the RAII object and the raw pointer. for instance
CComPtr<IFoo> GetAFoo();
Calling SomeCall will most likely not work in this scenario, because the pFoo object is already dead. What for? The value was returned using ref count 1 from GetAFoo assigned by pFoo, and then decreased to 0 and removed because the temporary value fell out of scope.
source share