Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Enterprise
Expertise: Intermediate
Aug 6, 1999

Use Cogetclassobject Instead Of Cocreateinstance While Creating COM Components

In most cases, you can use CoCreateInstance and forget about CoGetClassObject. Function CoGetClassObject returns the pointer to the desired component's class factory and not the component itself. The desired component is created using the the pointer returned from the function CoGetClassObject while the CoCreateInstance returns the requested interface pointer to that component (it creates the component using IClassFactory internally).

However, there are two cases where you should use CoGetClassObject instead of CoCreateInstance. First, you must use CoGetClassObject if you want to create object using a creation interface other than IClassFactory (say if you want to use IClassFactory2). Second, if you want to create a bunch of components at the same time, it is more efficient to create the class factory for all of the components instead of creating and releasing the class factory for every instance of a component.

Jai Bardhan
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date