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?
You use CoCreateInstance to ask COM to create an object. Usually it detects what DLL will fulfill the request and calls the
corresponding DllGetClassObject (in case of inproc server). when you have to implement DllGetClassObject you will have to create an
(C++-)object that will implement the requested interface. You create an object at the hep with 'new'.
So, what's the problem?
An argument for CoCreateInstance is that the COM queries the registry to get the correct object with all information for aparment
and probably create it remotely. But there are situations, where an immediate creation with 'new' is OK.
Regards,
Helge