I'm in the process of implementing my first out-of-process COM server (my first COM server altogether, for that matter). I have followed the steps to write an IDL file, generate the code for the proxy/stub DLL, compile the DLL, and register it.
When I check the registry keys, I have
HKEY_CLASSES_ROOT/Interface/<GUID>
, whose vaue is (say) IMyApp
andHKEY_CLASSES_ROOT/Interface/<GUID>/ProxyStubClsid32
, whose value is <GUID>
, i.e. the same value as in the key nameI don't understand how the the second key's value can be the same <GUID>
value as in the key name, because my current understanding is that
HKEY_CLASSES_ROOT/Interface/<GUID>
, GUID is an interface IDProxyStubClsid32
is not an interface ID, but a class ID referring to the component that implements the above interfaceHKEY_CLASSES_ROOT/CLSID/<GUID>/InprocServer32
(where GUID is the above class ID) points to the proxy DLLHow, then, can the value of HKEY_CLASSES_ROOT/Interface/<GUID>/ProxyStubClsid32
hold the same value GUID if one is an interface ID and the other is a class ID?
EDIT: I'm still hoping for an answer to this one. To put it short: Since a component and an interface are two different things, how can the same ID be used for both?
Your basic understanding of the way Guids are used in COM is correct. Notable first is that an interface and a coclass having the same guid is not a problem. They live in different registry keys, HKCR\Interface vs HKCR\CLSID and it is always clear in COM whether you are looking up a IID or a CLSID.
Second is the IDL you wrote. Note that there's no place there to specify the CLSID of the proxy, only the IIDs supported by the proxy and stub can be declared there.
Next, you need a wild goose chase through the way that the proxy/stub is autogenerated. The core Windows SDK header is RpcProxy.h, open it in a text editor to have a look see. The macro soup is very heavy but it does have a few decent comments that describe what's going on. The important RPC helper function is NdrDllRegisterProxy(), it registers the proxy and is called when you use Regsvr32.exe. Its 3rd argument specifies the CLSID of the proxy. I'll let you do the reading and just quote the important bits in the .h file:
Compiler switches:
-DPROXY_CLSID=clsid Specifies a class ID to be used by the proxy DLL.
This one you specify with Project + Properties, C/C++, Preprocessor, Preprocessor Definitions setting. Note that your project will not specify it.
Chasing through the soup then lands you on this one:
// if the user specified an override for the class id, it is
// PROXY_CLSID at this point
#ifndef PROXY_CLSID
#define GET_DLL_CLSID \
( aProxyFileList[0]->pStubVtblList[0] != 0 ? \
aProxyFileList[0]->pStubVtblList[0]->header.piid : 0)
#else //PROXY_CLSID
#define GET_DLL_CLSID &PROXY_CLSID
#endif //PROXY_CLSID
In other words, if you didn't specify the CLSID yourself (you didn't) then it uses the first IID in the stub table.
And that makes the ProxyStubClsid32 guid the same as the IID of your first interface. Feature, not a bug.