Creating an Instance of a COM, a Bird's Eye View
Let's see, from a bird's eye view, how the whole thing works. To get an interface to the ComInterface client, call:
IComInterface * pComInterface;
HRESULT hr= CoCreateInstance(CLSID_X, NULL,CLSCTX_ALL,IID_X,
(void**)& pComInterface);
if(hr == S_OK)
hr = pComInterface ->method x;
Let's see how this magical call to CoCreateInstance yields us the pointer to the interface, pComInterface, that we so dearly need.
CoCreateInstance calls:
CoGetClassObject(CLSID_X, CLSCTX_ALL /*dwClsContext*/, NULL, ,IID_X,
,[out]pointer to X interface);
CoGetClassObject invokes the COM Service Control Manager, which searches in the Registry using the CLSID_X. It finds the associated ComServer DLL, loads it into memory, and calls the DllGetClassObject method of the DLL.
From the diagram above, it can be seen that the DLL contains an object of ComClassFactory. Also note that ComClassFactory inherits from IClassFactory and implements its methods, mainly CreateInstance.
The DllGetClassObject can be implemeted like this:
{
ComClassFactory *pClassFactory ;
pClassFactory = new ComClassFactory;
hresult = pClassFactory -CreateInstance(NULL, ,IID_X,
[out]pointer to X interface)
}
From the diagram, you can see that ComClassFactory contains an object of ComClass.
Note that the ComClass inherits from IComInterface and implements all its methods. So, ComClassFactory :: CreateInstance(..) is implemented like so:
{
ComClass *pComClass;
pComClass = new ComClass; // create a new object
pComClass->QueryInterface( IID_X,[out]pointer to X interface)
Use the object pointer to call its implemented QueryInterface and return a pointer to the interface that we were seeking (one having IID_X). This is how we magically get our dear pointer to interface X.
Summary
CoCreateInstance(CLSID_X, NULL,CLSCTX_ALL,IID_X, (void**)&
pComInterface);
calls
CoGetClassObject(CLSID_X, CLSCTX_ALL /*dwClsContext*/, NULL, ,IID_X,
,[out]pointer to X interface);
which calls SCM to search in the Registry for the location of the DLL using CLSID_X, loads the dll, and calls
DllGetClassObject(CLSID_X, ,IID_X, ,[out]pointer to X interface);
which creates an object of ComClassFactory:
ComClassFactory *pClassFactory ; pClassFactory = new ComClassFactory;
and calls
hresult = pClassFactory -CreateInstance(NULL, ,IID_X,
[out]pointer to X interface)
which creates an object of ComClass,
ComClass *pComClass;
pComClass = new ComClass; // create a new object
and calls
pComClass->QueryInterface( IID_X,[out]pointer to X interface)
which gives us the pointer to the X interface that we so needed.
Alex C. Punnen alexcpn@hotmail.com

Comments
Cosmopolitan Gossip - gucci Thought of as A Must These days
Posted by incockDak on 03/29/2013 08:03amThe Secret master the gucci-scene Is Quite Easy! [url=http://growth-management.alachua.fl.us/comprehensive_planning/gucci.html]ããã¯[/url] Cutting edge gucci Guide Unveil The Right Way To Rule The gucci Scene [url=http://growth-management.alachua.fl.us/comprehensive_planning/saclongchamp.php]Sac longchamp[/url] HmvIotZnxNcn [url=http://running-nike0.seesaa.net/]ãã¤ã[/url]WvgCnqIgkKga [[url=http://free-nike-nikeo.seesaa.net/]ãã¤ã ããªã¼[/url]DmxHijBmaMro [url=http://xn--nike-ul4c5c5fyqb.seesaa.net/]nike ã¹ãã¼ã«ã¼[/url]RjdOkyLltSgj [url=http://nikejapan0.seesaa.net/]ã¹ãã¼ã«ã¼ãã¤ã[/url]CkwZhlZueSfj [url=http://nikesneakersjp.seesaa.net/]nike ã¹ãã¼ã«ã¼[/url]TlrHaeJgjTjr [url=http://nikegolf00.seesaa.net/]ãã¤ã[/url]WqeQvkGalFoh [url=http://nikeshoes00.seesaa.net/]nike ã·ã¥ã¼ãº[/url]CmbCwxCmxHkp [url=http://sneaker-adidas-jp.seesaa.net/]ã¹ãã¼ã«ã¼ adidas[/url]JuzOcxPhxKaf
ReplyA bvlgari purse Service Speak -- Those Who really cares about zilch is announced the champ?!?
Posted by expopmerm on 03/22/2013 08:30pm[url=http://www.mcmoutletjpinoue.com]mcm ããã°[/url] mcm Is Giving Completely New Life For An Old Issue. . . Metallic Standardized [url=http://www.mcmsalejapanoka.com]mcm ããã°[/url] mcm Is Giving Completely New Lifespan To A Old Subject: Metallic Standards [url=http://www.mcmzankijpshop.com]mcm ããã°[/url] Here Is A Strategy That Is Also Assisting mcm-Industry Experts To Advance [url=http://www.mcmstorejpkodo.com]mcm ããã°[/url] mcm Counterfeits : A Fantastic mcm 'Cheat' Which Fools 97% Of The Users Concise report unwraps the incontestable information regarding bvlgari purse and also the way it could have an effect people. [url=http://www.bvlgarishopjprie.com]ãã«ã¬ãª[/url] An ideal strategy for bvlgari purse that you will learn about right now. [url=http://www.bvlgarioutletshopjp.com]ãã«ã¬ãª[/url] Find who's writing about bvlgari purse and the particular reason why you ought to get worried. [url=http://www.bvlgarisalekodojp.com]ãã«ã¬ãª 財å¸[/url] Innovative publishing unveils the low down of bvlgari purse in addition , the reasons why you need to take action straight away. [url=http://www.bvlgarisakaijpsale.com]ãã«ã¬ãª æè¨[/url] New essay tells the know-how for bvlgari purse and as a result the reasons you have got to take action soon. [url=http://www.bvlgariaokisalejp.com]ãã«ã¬ãªã¤ã«ã«ãã§[/url] Marketplace News : bvlgari purse Understood to be A Must In the present day Be The 1st To View What Scientists Are Saying Over [url=http://www.mcmbagsjphadori.com]mcm ããã°[/url] mcm The Most Common Myths Vs. The Unquestionable Aspects
ReplyI am getting an error while trying to register my component? i have logged in as Restricted user.
Posted by sreeharsha.kottadamane on 06/23/2007 11:41amHi, I am getting an error while trying to register my component? i have logged in as Restricted user.The error that i am getting is "Class not registered". Can you please help me ? I want to register my component programmatically.
ReplyExcellent! Thank you.
Posted by Legacy on 12/05/2003 12:00amOriginally posted by: SAS
Succinct and informative.
Reply
Tell me how you fuck your mother if you have no sister
Posted by Legacy on 09/08/2003 12:00amOriginally posted by: Good man
s
Reply
Can you tell me how to register a COM exe server?
Posted by Legacy on 06/18/2003 12:00amOriginally posted by: Bill Gates
Tell me plz
Reply
Great Work
Posted by Legacy on 06/17/2003 12:00amOriginally posted by: John
Thanks alex nice work
Reply
What is the point of this article?
Posted by Legacy on 06/16/2003 12:00amOriginally posted by: Goo
What is the point of this article?
Reply